Skip to content

Commit

Permalink
Merge pull request #770 from StepicOrg/release/1.160
Browse files Browse the repository at this point in the history
Release/1.160
  • Loading branch information
rostikjoystick authored Feb 11, 2021
2 parents 88c33b7 + 2f1419a commit c4cd223
Show file tree
Hide file tree
Showing 21 changed files with 387 additions and 32 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ dependencies {
implementation libraries.fragmentKtx
implementation libraries.room
kapt libraries.roomCompiler
implementation libraries.browser

implementation libraries.archCompiler
implementation libraries.archViewModel
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/org/stepic/droid/analytic/AmplitudeAnalytic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,26 @@ interface AmplitudeAnalytic {
object Achievements {
const val NOTIFICATION_RECEIVED = "Achievement notification received"

const val SCREEN_OPENED = "Achievements screen opened"
const val POPUP_OPENED = "Achievement popup opened"
const val SHARE_PRESSED = "Achievement share pressed"

object Params {
const val KIND = "achievement_kind"
const val LEVEL = "achievement_level"

const val IS_PERSONAL = "is_personal"

const val SOURCE = "source"
}

object Values {
/***
* Source
*/
const val PROFILE = "profile"
const val ACHIEVEMENT_LIST = "achievement-list"
const val NOTIFICATION = "notification"
}
}

Expand Down Expand Up @@ -307,4 +324,46 @@ interface AmplitudeAnalytic {
const val REVIEW_START_REVIEW = "Review Start Review"
const val REVIEW_VIEW_REVIEW = "Review View Review"
}

object Settings {
const val SCREEN_OPENED = "Settings screen opened"
}

object Sections {
const val SCREEN_OPENED = "Sections screen opened"

object Params {
const val COURSE = "course"
const val TITLE = "title"
}
}

object Discussions {
const val SCREEN_OPENED = "Discussions screen opened"

object Params {
const val SOURCE = "source"
}

object Values {
/***
* Source
*/
const val DISCUSSION = "discussion"
const val REPLY = "reply"
const val DEFAULT = "default"
}
}

object Certificates {
const val SCREEN_OPENED = "Certificates screen opened"
}

object ChromeTab {
const val CHROME_TAB_OPENED = "Chrome tab opened"

object Params {
const val FALLBACK = "fallback"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ constructor(
analytic,
sharedPreferenceHelper,

name = "course_purchase_webview",
name = "course_purchase_webview_2",
groups = Group.values()
) {
enum class Group(
val isInAppWebViewUsed: Boolean
) : SplitTest.Group {
Control(isInAppWebViewUsed = false),
InAppWebview(isInAppWebViewUsed = true)
enum class Group : SplitTest.Group {
Control,
InAppWebview,
ChromeTab
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -274,6 +276,7 @@ public void showCertificates(Context context) {
@Override
public void showCertificates(Context context, long userId) {
analytic.reportEvent(Analytic.Screens.USER_OPEN_CERTIFICATES, userId + "");
analytic.reportAmplitudeEvent(AmplitudeAnalytic.Certificates.SCREEN_OPENED);
Intent intent = CertificatesActivity.Companion.createIntent(context, userId);
context.startActivity(intent);
}
Expand Down Expand Up @@ -359,6 +362,7 @@ public void showVideo(@NotNull Fragment sourceFragment, @NotNull VideoPlayerMedi
@Override
public void showSettings(Activity sourceActivity) {
analytic.reportEvent(Analytic.Screens.SHOW_SETTINGS);
analytic.reportAmplitudeEvent(AmplitudeAnalytic.Settings.SCREEN_OPENED);
Intent intent = new Intent(sourceActivity, SettingsActivity.class);
sourceActivity.startActivity(intent);
sourceActivity.overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
Expand Down Expand Up @@ -596,6 +600,9 @@ public void openRemindPassword(AppCompatActivity context) {
@Override
public void showAchievementsList(Context context, long userId, boolean isMyProfile) {
Intent intent = AchievementsListActivity.Companion.createIntent(context, userId, isMyProfile);
Map<String, Object> params = new HashMap<>();
params.put(AmplitudeAnalytic.Achievements.Params.IS_PERSONAL, isMyProfile);
analytic.reportAmplitudeEvent(AmplitudeAnalytic.Achievements.SCREEN_OPENED, params);
context.startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ sealed class CourseListItem {
}

class PlaceHolder(val courseId: Long = -1) : CourseListItem()

object ViewAll : CourseListItem()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ constructor(

is CourseListItem.PlaceHolder ->
it.courseId

is CourseListItem.ViewAll ->
null
}
}
?.let { lastCourseId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.dialog_achievement_details.view.*
import org.stepic.droid.R
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.base.App
import org.stepik.android.view.glide.ui.extension.wrapWithGlide
import org.stepik.android.domain.achievement.model.AchievementItem
Expand All @@ -21,19 +23,24 @@ class AchievementDetailsDialog : DialogFragment() {
companion object {
const val TAG = "achievement_details_dialog"

fun newInstance(achievementItem: AchievementItem, canShareAchievement: Boolean): AchievementDetailsDialog =
fun newInstance(achievementItem: AchievementItem, canShareAchievement: Boolean, source: String): AchievementDetailsDialog =
AchievementDetailsDialog()
.apply {
this.achievementItem = achievementItem
this.canShare = canShareAchievement
this.source = source
}
}

@Inject
lateinit var analytic: Analytic

@Inject
lateinit var achievementResourceResolver: AchievementResourceResolver

private var achievementItem: AchievementItem by argument()
private var canShare: Boolean by argument()
private var source: String by argument()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -95,6 +102,14 @@ class AchievementDetailsDialog : DialogFragment() {
}

private fun shareAchievement() {
analytic.reportAmplitudeEvent(
AmplitudeAnalytic.Achievements.SHARE_PRESSED,
mapOf(
AmplitudeAnalytic.Achievements.Params.SOURCE to source,
AmplitudeAnalytic.Achievements.Params.KIND to achievementItem.kind,
AmplitudeAnalytic.Achievements.Params.LEVEL to achievementItem.currentLevel
)
)
val intent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_TEXT, getString(R.string.achievement_share, achievementResourceResolver.resolveTitleForKind(achievementItem.kind)))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.error_no_connection_with_button.*
import kotlinx.android.synthetic.main.fragment_achievements_list.*
import org.stepic.droid.R
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.base.App
import org.stepic.droid.ui.util.initCenteredToolbar
import org.stepik.android.domain.achievement.model.AchievementItem
Expand All @@ -36,6 +38,9 @@ class AchievementsListFragment : Fragment(), AchievementsView {
}
}

@Inject
internal lateinit var analytic: Analytic

@Inject
internal lateinit var viewModelFactory: ViewModelProvider.Factory

Expand Down Expand Up @@ -106,8 +111,16 @@ class AchievementsListFragment : Fragment(), AchievementsView {
}

private fun onAchievementClicked(item: AchievementItem) {
analytic.reportAmplitudeEvent(
AmplitudeAnalytic.Achievements.POPUP_OPENED,
mapOf(
AmplitudeAnalytic.Achievements.Params.SOURCE to AmplitudeAnalytic.Achievements.Values.ACHIEVEMENT_LIST,
AmplitudeAnalytic.Achievements.Params.KIND to item.kind,
AmplitudeAnalytic.Achievements.Params.LEVEL to item.currentLevel
)
)
AchievementDetailsDialog
.newInstance(item, isMyProfile)
.newInstance(item, isMyProfile, AmplitudeAnalytic.Achievements.Values.ACHIEVEMENT_LIST)
.showIfNotExists(childFragmentManager, AchievementDetailsDialog.TAG)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.stepik.android.view.base.web;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
* Helper class for Custom Tabs.
*/
public final class CustomTabsHelper {
private static final String TAG = "CustomTabsHelper";
static final String STABLE_PACKAGE = "com.android.chrome";
static final String BETA_PACKAGE = "com.chrome.beta";
static final String DEV_PACKAGE = "com.chrome.dev";
static final String LOCAL_PACKAGE = "com.google.android.apps.chrome";
private static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE =
"android.support.customtabs.extra.KEEP_ALIVE";
private static final String ACTION_CUSTOM_TABS_CONNECTION =
"android.support.customtabs.action.CustomTabsService";

private static String sPackageNameToUse;

private CustomTabsHelper() {}

/**
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
* the one chosen by the user if there is one, otherwise makes a best effort to return a
* valid package name.
*
* This is <strong>not</strong> threadsafe.
*
* @param context {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;

PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}

// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}

// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}

/**
* Used to check whether there is a specialized handler for a given intent.
* @param intent The intent to check with.
* @return Whether there is a specialized handler for the given intent.
*/
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
try {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> handlers = pm.queryIntentActivities(
intent,
PackageManager.GET_RESOLVED_FILTER);
if (handlers.size() == 0) {
return false;
}
for (ResolveInfo resolveInfo : handlers) {
IntentFilter filter = resolveInfo.filter;
if (filter == null) continue;
if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
if (resolveInfo.activityInfo == null) continue;
return true;
}
} catch (RuntimeException e) {
Log.e(TAG, "Runtime exception while getting specialized handlers");
}
return false;
}
}
Loading

0 comments on commit c4cd223

Please sign in to comment.