Skip to content

Commit

Permalink
Merge pull request #96 from StepicOrg/release/1.42
Browse files Browse the repository at this point in the history
Release/1.42
  • Loading branch information
KirillMakarov authored Sep 7, 2017
2 parents d9b8d15 + b6c637c commit e2c738b
Show file tree
Hide file tree
Showing 99 changed files with 1,277 additions and 593 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ apply plugin: 'kotlin-android-extensions'
def globalConf = rootProject.ext
android {

compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion rootProject.androidCompileSdkVersion
buildToolsVersion rootProject.androidBuildToolsVersion

signingConfigs {
debug {
Expand Down Expand Up @@ -36,8 +36,8 @@ android {
applicationId "org.stepic.droid"
minSdkVersion rootProject.androidMinSdkVersion
targetSdkVersion rootProject.androidTargetSdkVersion
versionCode 168
versionName "1.41.2"
versionCode 170
versionName "1.42"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class LaunchActivity : BackToExitActivityBase(), LoginView {

signInWithEmail.setOnClickListener {
analytic.reportEvent(Analytic.Interaction.CLICK_SIGN_IN)
screenManager.showLogin(this@LaunchActivity, courseFromExtra)
screenManager.showLogin(this@LaunchActivity, courseFromExtra, null)
}


Expand Down Expand Up @@ -371,6 +371,10 @@ class LaunchActivity : BackToExitActivityBase(), LoginView {
openMainFeed()
}

override fun onSocialLoginWithExistingEmail(email: String) {
screenManager.showLogin(this, courseFromExtra, email)
}

private fun openMainFeed() {
screenManager.showMainFeed(this, courseFromExtra)
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,20 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activities.MainFeedActivity"/>
</activity>


<activity
android:name=".ui.activities.NotificationSettingsActivity"
android:enabled="@bool/notification_activity_enabled"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.NOTIFICATION_PREFERENCES"/>
</intent-filter>
</activity>


<activity
android:name=".ui.activities.FeedbackActivity"
android:launchMode="singleTop"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/stepic/droid/analytic/Analytic.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ interface Screens {
String OPEN_STORE = "Open google play, estimation";
String TRY_OPEN_VIDEO = "video is tried to show";
String SHOW_SETTINGS = "show settings";
String SHOW_NOTIFICATION_SETTINGS = "show_notification_settings";
String SHOW_STORAGE_MANAGEMENT = "show storage management";
String OPEN_COMMENT_NOT_AVAILABLE = "comment: not available";
String OPEN_COMMENT = "comments: open oldList";
Expand Down Expand Up @@ -347,7 +348,6 @@ interface Exam {
interface Profile {
String CLICK_INSTRUCTOR = "profile_click_instructor";
String CLICK_USER_IN_COMMENT = "profile_click_in_comment";
String CLICK_OPEN_MY_PROFILE_IMAGE = "profile_click_open_my"; //click on image
String SHOW_LOCAL = "profile_show_my";
String OPEN_NO_INTERNET = "profile_no_internet";
String STREAK_NO_INTERNET = "profile_no_internet_streak";
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/org/stepic/droid/base/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.stepic.droid.di.storage.DaggerStorageComponent
import org.stepic.droid.fonts.FontType
import org.stepic.droid.fonts.FontsProvider
import org.stepic.droid.storage.InitialDownloadUpdater
import org.stepic.droid.util.NotificationChannelInitializer
import timber.log.Timber
import uk.co.chrisjenx.calligraphy.CalligraphyConfig
import javax.inject.Inject
Expand Down Expand Up @@ -96,9 +97,10 @@ class App : Application() {
// init AppMetrica SDK
YandexMetrica.activate(applicationContext, "fd479031-bdf4-419e-8d8f-6895aab23502")
YandexMetrica.enableActivityAutoTracking(this)
initChannels()
}

override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
private fun initChannels() {
NotificationChannelInitializer.initNotificationChannels(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.ContextMenu;
Expand All @@ -18,7 +17,6 @@
import org.stepic.droid.R;
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.core.dropping.contract.DroppingListener;
import org.stepic.droid.core.dropping.contract.DroppingPoster;
import org.stepic.droid.core.presenters.PersistentCourseListPresenter;
import org.stepic.droid.core.presenters.contracts.FilterForCoursesView;
import org.stepic.droid.model.Course;
Expand All @@ -28,16 +26,12 @@
import org.stepic.droid.ui.util.ContextMenuRecyclerView;
import org.stepic.droid.ui.util.OnBackClickListener;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.ColorUtil;
import org.stepic.droid.util.ContextMenuCourseUtil;

import java.util.List;

import javax.inject.Inject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class CoursesDatabaseFragmentBase extends CourseListFragmentBase implements FilterForCoursesView, OnBackClickListener, DroppingListener {
private static final int FILTER_REQUEST_CODE = 776;

Expand All @@ -46,9 +40,6 @@ public abstract class CoursesDatabaseFragmentBase extends CourseListFragmentBase
@Inject
PersistentCourseListPresenter courseListPresenter;

@Inject
DroppingPoster droppingPoster;

@Inject
Client<DroppingListener> droppingClient;

Expand Down Expand Up @@ -154,11 +145,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMen
}

MenuInflater inflater = getActivity().getMenuInflater();
if (courses.get(position).getEnrollment() != 0) {
inflater.inflate(R.menu.course_context_menu, menu);
} else {
inflater.inflate(R.menu.course_context_not_enrolled_menu, menu);
}
inflater.inflate(ContextMenuCourseUtil.INSTANCE.getMenuResource(courses.get(position)), menu);
}

@Override
Expand All @@ -179,45 +166,11 @@ public boolean onContextItemSelected(MenuItem item) {

private void dropCourse(int position) {
if (position >= courses.size() || position < 0) {
Toast.makeText(getContext(), R.string.try_in_web_drop, Toast.LENGTH_SHORT).show();
//tbh, it should be illegal state
return;
}
final Course course = courses.get(position);
if (course.getEnrollment() == 0) {
Toast.makeText(getContext(), R.string.you_not_enrolled, Toast.LENGTH_SHORT).show();
return;
}
Call<Void> drop = getApi().dropCourse(course.getCourseId());
if (drop != null) {
drop.enqueue(new Callback<Void>() {
Course localRef = course;

@Override
public void onResponse(Call<Void> call, Response<Void> response) {
getThreadPoolExecutor().execute(new Runnable() {
@Override
public void run() {
getDatabaseFacade().deleteCourse(localRef, Table.enrolled);

if (getDatabaseFacade().getCourseById(course.getCourseId(), Table.featured) != null) {
localRef.setEnrollment(0);
getDatabaseFacade().addCourse(localRef, Table.featured);
}

}
});

droppingPoster.successDropCourse(localRef);
}

@Override
public void onFailure(Call<Void> call, Throwable t) {
droppingPoster.failDropCourse(localRef);
}
});
} else {
Toast.makeText(getContext(), R.string.cant_drop, Toast.LENGTH_SHORT).show();
}
droppingPresenter.dropCourse(course);
}

private void showInfo(int position) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/stepic/droid/base/FragmentBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import android.os.Bundle
import android.support.annotation.DrawableRes
import android.support.v4.app.Fragment
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.inputmethod.InputMethodManager
import butterknife.ButterKnife
import butterknife.Unbinder
import org.stepic.droid.R
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.concurrency.MainHandler
import org.stepic.droid.configuration.Config
Expand All @@ -21,6 +23,7 @@ import org.stepic.droid.preferences.UserPreferences
import org.stepic.droid.storage.CancelSniffer
import org.stepic.droid.storage.IDownloadManager
import org.stepic.droid.storage.operations.DatabaseFacade
import org.stepic.droid.ui.activities.contracts.BottomNavigationViewRoot
import org.stepic.droid.ui.util.CloseIconHolder
import org.stepic.droid.util.resolvers.CoursePropertyResolver
import org.stepic.droid.util.resolvers.text.TextResolver
Expand Down Expand Up @@ -168,4 +171,18 @@ open class FragmentBase : Fragment() {
protected fun nullifyActivityBackground() {
activity?.window?.decorView?.background = null
}

/**
* Apply margin if activity has bottom navigation bar
*/
protected fun applyBottomMarginForRootView() {
activity as? BottomNavigationViewRoot ?: return
val rootView: ViewGroup = getRootView() ?: throw IllegalStateException("For using applyBottomMarginForRootView, you should override getRootView() in your fragment.")

val layoutParams = rootView.layoutParams as ViewGroup.MarginLayoutParams

layoutParams.bottomMargin = resources.getDimensionPixelSize(R.dimen.bottom_navigation_height)
}

protected open fun getRootView(): ViewGroup? = null
}
4 changes: 3 additions & 1 deletion app/src/main/java/org/stepic/droid/core/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface ScreenManager {

void showRegistration(Activity sourceActivity, @Nullable Course course);

void showLogin(Activity sourceActivity, @Nullable Course course);
void showLogin(Activity sourceActivity, @Nullable Course course, @Nullable String email);

void showMainFeed(Context sourceActivity, @Nullable Course course);

Expand Down Expand Up @@ -84,6 +84,8 @@ public interface ScreenManager {

void showSettings(Activity sourceActivity);

void showNotificationSettings(Activity sourceActivity);

void showStorageManagement(Activity activity);

void openInWeb(Activity context, String path);
Expand Down
36 changes: 28 additions & 8 deletions app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.TaskStackBuilder;
Expand Down Expand Up @@ -46,6 +48,7 @@
import org.stepic.droid.ui.activities.LoginActivity;
import org.stepic.droid.ui.activities.MainFeedActivity;
import org.stepic.droid.ui.activities.NewCommentActivity;
import org.stepic.droid.ui.activities.NotificationSettingsActivity;
import org.stepic.droid.ui.activities.NotificationsActivity;
import org.stepic.droid.ui.activities.PhotoViewActivity;
import org.stepic.droid.ui.activities.ProfileActivity;
Expand Down Expand Up @@ -154,12 +157,15 @@ public void showRegistration(Activity sourceActivity, @Nullable Course course) {
}

@Override
public void showLogin(Activity sourceActivity, @Nullable Course course) {
public void showLogin(Activity sourceActivity, @Nullable Course course, @Nullable String email) {
analytic.reportEvent(Analytic.Screens.SHOW_LOGIN);
Intent loginIntent = new Intent(sourceActivity, LoginActivity.class);
if (course != null) {
loginIntent.putExtra(AppConstants.KEY_COURSE_BUNDLE, (Parcelable) course);
}
if (email != null) {
loginIntent.putExtra(AppConstants.KEY_EMAIL_BUNDLE, email);
}
sourceActivity.startActivity(loginIntent);
}

Expand Down Expand Up @@ -251,11 +257,7 @@ public Intent getCertificateIntent() {

@Override
public void showCertificates(Context context) {
Intent intent = new Intent(context, CertificatesActivity.class);
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
showMainFeed(context, MainFeedActivity.CERTIFICATE_INDEX);
}

@Override
Expand All @@ -274,7 +276,7 @@ public void showFindCourses(Context context) {

@Override
public Intent getShowFindCoursesIntent(Context context) {
int index = MainFeedActivity.Companion.getFindCoursesIndex();
int index = MainFeedActivity.FIND_COURSES_INDEX;
return getFromMainActivityIntent(context, index);
}

Expand Down Expand Up @@ -340,6 +342,24 @@ public void showSettings(Activity sourceActivity) {
sourceActivity.overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
}

@Override
public void showNotificationSettings(Activity sourceActivity) {
analytic.reportEvent(Analytic.Screens.SHOW_NOTIFICATION_SETTINGS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//show system settings
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, sourceActivity.getPackageName());
sourceActivity.startActivity(intent);
} else {
//show app notification settings
//(SDK < 26)
Intent intent = new Intent(sourceActivity, NotificationSettingsActivity.class);
sourceActivity.startActivity(intent);
sourceActivity.overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
}
}

@Override
public void showStorageManagement(Activity activity) {
analytic.reportEvent(Analytic.Screens.SHOW_STORAGE_MANAGEMENT);
Expand Down Expand Up @@ -382,7 +402,7 @@ public void openFeedbackActivity(Activity activity) {

@Override
public Intent getMyCoursesIntent(@NotNull Context context) {
int index = MainFeedActivity.Companion.getMyCoursesIndex();
int index = MainFeedActivity.MY_COURSES_INDEX;
return getFromMainActivityIntent(context, index);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.stepic.droid.core.dropping.contract

import android.support.annotation.MainThread
import org.stepic.droid.model.Course

interface DroppingPoster {

@MainThread
fun successDropCourse(course: Course)

@MainThread
fun failDropCourse(course: Course)
}
Loading

0 comments on commit e2c738b

Please sign in to comment.