Skip to content

Commit

Permalink
Merge pull request #156 from StepicOrg/release/1.46
Browse files Browse the repository at this point in the history
Release/1.46
  • Loading branch information
KirillMakarov authored Nov 2, 2017
2 parents a62ad38 + 0f2ec68 commit 899e5a2
Show file tree
Hide file tree
Showing 220 changed files with 3,349 additions and 2,422 deletions.
33 changes: 14 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "org.stepic.droid"
minSdkVersion rootProject.androidMinSdkVersion
targetSdkVersion rootProject.androidTargetSdkVersion
versionCode 188
versionName "1.45.8"
versionCode 192
versionName "1.46.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -155,13 +155,10 @@ dependencies {
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'

compile 'joda-time:joda-time:2.8'
compile 'org.joda:joda-convert:1.3.1'

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile "com.squareup.retrofit2:retrofit:${rootProject.retrofitVersion}"
compile "com.squareup.retrofit2:converter-gson:${rootProject.retrofitVersion}"
compile "com.squareup.retrofit2:adapter-rxjava2:${rootProject.retrofitVersion}"

// AppMetrica from maven central. Protobuf will be included as dependency.
compile 'com.yandex.android:mobmetricalib:2.62'
Expand Down Expand Up @@ -191,7 +188,11 @@ dependencies {

compile 'com.github.chrisbanes:PhotoView:1.3.1'

compile 'com.github.h6ah4i:android-advancedrecyclerview:develop-SNAPSHOT'

compile('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar')
//depends on (remove this library in future or be care, when update support libs)
// | +--- com.android.support:appcompat-v7:27.0.0 (*)
// | \--- com.android.support:recyclerview-v7:27.0.0 (*)

compile 'com.android.support.constraint:constraint-layout:1.0.2'

Expand All @@ -203,6 +204,9 @@ dependencies {
//add exo player for video (change playback speed supported)
compile 'com.google.android.exoplayer:exoplayer-core:r2.5.3'

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.5'

oldReleaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakCanaryVersion}"
testCompile "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakCanaryVersion}"
androidTestCompile "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakCanaryVersion}"
Expand All @@ -214,6 +218,7 @@ dependencies {
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:2.7.21'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'joda-time:joda-time:2.8'

androidTestCompile 'org.hamcrest:hamcrest-library:1.3'

Expand All @@ -233,16 +238,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.5'
}

repositories {
jcenter()
maven {
url "https://jitpack.io"
}
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LaunchActivity : SmartLockActivityBase(), LoginView {
}


private var progressLogin: ProgressDialog? = null
private var progressLogin: LoadingProgressDialog? = null
private lateinit var progressHandler: ProgressHandler
private lateinit var callbackManager: CallbackManager

Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/org/stepic/droid/analytic/Analytic.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ interface Interaction {
String CLICK_CHOOSE_NOTIFICATION_INTERVAL = "click_choose_notification_interval";
String CLICK_PRIVACY_POLICY = "click_privacy_policy";
String CLICK_TERMS_OF_SERVICE = "click_terms_of_service";
String POSITIVE_MATERIAL_DIALOG_INVITATION = "material_dialog_invite_positive";
String NEGATIVE_MATERIAL_DIALOG_INVITATION = "material_dialog_invite_negative";

String INVITE_DIALOG_DISMISSED = "invite_dialog_dismissed";
interface InviteDialogDismissType {
String LEAVE = "leave";
String SHARE = "share";
}
String INVITE_DIALOG_BROKEN = "invite_dialog_broken";

String SHOW_MATERIAL_DIALOG_INVITATION = "materdial_dialog_invite_shown";
String INVITATION_PREVENTED = "invite_prevented";
String CLICK_CONTINUE_COURSE = "click_continue_course";
String CLICK_COURSE = "click_course";
String CLICK_PROFILE_BEFORE_LOADING = "click_profile_before_loading";
Expand Down Expand Up @@ -243,7 +248,6 @@ interface Error {
String ILLEGAL_STATE_PREVIOUS_LESSON = "cant_show_previous_lesson";
String FAIL_PUSH_STEP_VIEW = "fail_push_step_view";
String NO_INTERNET_EXISTING_ATTEMPTS = "no_internet_existing_attempts";
String DOWNLOAD_ID_NEGATIVE = "download_id_negative";
String DOWNLOAD_FAILED = "download_failed";
String STREAK_ON_STEP_SOLVED = "streak_on_step_solved";
String GOOGLE_SERVICES_TOO_OLD = "google_services_too_old";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.my_courses_menu, menu);
inflater.inflate(R.menu.filter_courses_menu, menu);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
Expand Down Expand Up @@ -175,12 +174,7 @@ protected boolean wasLaunchedFromRecents() {

@Nullable
protected Course getCourseFromExtra() {
Parcelable course = getIntent().getParcelableExtra(AppConstants.KEY_COURSE_BUNDLE);
if (course != null && course instanceof Course) {
return (Course) course;
} else {
return null;
}
return getIntent().getParcelableExtra(AppConstants.KEY_COURSE_BUNDLE);
}


Expand Down
53 changes: 46 additions & 7 deletions app/src/main/java/org/stepic/droid/code/ui/CodeAnalyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ object CodeAnalyzer {
)
)

private val quotes = hashSetOf(
"\"", "'"
private val quotes = hashMapOf(
"\"" to "\"",
"'" to "'"
)

private val pairedSymbols = brackets + quotes


private fun getIndentForCurrentLine(cursorPosition: Int, text: String) : Int {
val prevLineStart = text.substring(0, cursorPosition).lastIndexOf(LINE_BREAK)
return text.countWhile (prevLineStart + 1) { Character.isWhitespace(it) && it != LINE_BREAK }
Expand Down Expand Up @@ -58,16 +62,51 @@ object CodeAnalyzer {
in brackets -> {
val next = getNextSymbol(start + 1, text)
if (next == null || Character.isWhitespace(next[0]) || next in brackets.values) { // don't want auto bracket if there is a statement next
codeEditor.editableText.insert(start + count, brackets[inserted])
codeEditor.setSelection(start + count)
insertTextAfterCursor(start, count, codeEditor, brackets[inserted])
}
}

in brackets.values -> {
onClosingSymbolInserted(start, count, codeEditor, inserted, text)
}

in quotes -> {
val next = getNextSymbol(start + 1, text)
if (next == null || Character.isWhitespace(next[0])) { // don't want auto quote if there is a statement next
codeEditor.editableText.insert(start, inserted)
codeEditor.setSelection(start + count)
val prev = getPrevSymbol(start, text)
if ((next == null || Character.isWhitespace(next[0])) && prev != inserted) { // don't want auto quote if there is a statement next
insertTextAfterCursor(start, count, codeEditor, inserted)
} else {
onClosingSymbolInserted(start, count, codeEditor, inserted, text)
}
}
}
}

private fun insertTextAfterCursor(start: Int, count: Int, codeEditor: CodeEditor, textToInsert: String?) {
codeEditor.withoutAnalyze {
it.editableText.insert(start + count, textToInsert)
it.setSelection(start + count)
}
}

private fun onClosingSymbolInserted(start: Int, count: Int, codeEditor: CodeEditor, inserted: String, text: String) {
if (inserted == text.substringOrNull(start + count, start + 2 * count)) {
codeEditor.withoutAnalyze {
it.editableText.replace(start, start + count, "")
it.setSelection(start + count)
}
}
}

fun onTextReplaced(start: Int, count: Int, codeEditor: CodeEditor, replaced: String) {
val text = codeEditor.editableText.toString()
when (replaced) {
in pairedSymbols -> {
val next = getNextSymbol(start, text)
if (next != null && next == pairedSymbols[replaced]) {
codeEditor.withoutAnalyze {
it.editableText.replace(start, start + next.length, "")
}
}
}
}
Expand Down
35 changes: 25 additions & 10 deletions app/src/main/java/org/stepic/droid/code/ui/CodeEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.os.Build
import android.os.Parcelable
import android.support.annotation.ColorInt
import android.support.v7.widget.AppCompatEditText
Expand All @@ -27,6 +26,7 @@ import org.stepic.droid.code.highlight.ParserContainer
import org.stepic.droid.code.highlight.syntaxhighlight.ParseResult
import org.stepic.droid.code.highlight.themes.CodeTheme
import org.stepic.droid.code.highlight.themes.Presets
import org.stepic.droid.ui.util.removeGlobalLayoutListener
import org.stepic.droid.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand Down Expand Up @@ -88,12 +88,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
set(value) {
field?.let { container ->
container.viewTreeObserver.removeOnScrollChangedListener(onScrollChangedListener)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
container.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener)
} else {
@Suppress("DEPRECATION") //use only on old API
container.viewTreeObserver.removeGlobalOnLayoutListener(onGlobalLayoutListener)
}
container.viewTreeObserver.removeGlobalLayoutListener(onGlobalLayoutListener)
}

value?.let { container ->
Expand All @@ -103,6 +98,8 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
field = value
}

var isCodeAnalyzerEnabled = true

override fun onAttachedToWindow() {
super.onAttachedToWindow()

Expand Down Expand Up @@ -227,17 +224,28 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
private var insertedStart: Int = 0
private var insertedCount: Int = 0

private var replacedStart: Int = 0
private var replacedCount: Int = 0
private var replacedText: String = ""

override fun afterTextChanged(editable: Editable) {
lines = text.toString().lines()
CodeAnalyzer.onTextInserted(insertedStart, insertedCount, this)
if (isCodeAnalyzerEnabled) {
CodeAnalyzer.onTextReplaced(replacedStart, replacedCount, this, replacedText)
CodeAnalyzer.onTextInserted(insertedStart, insertedCount, this)
}
highlightBrackets(selectionStart)
highlightPublisher.onNext(editable)
requestLayout()
}

override fun beforeTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, count: Int) {}
override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {
replacedStart = start
replacedCount = count
replacedText = text.substring(start, start + count)
}

override fun onTextChanged(text: CharSequence, start: Int, lengthBefore: Int, count: Int) {
override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {
insertedStart = start
insertedCount = count
}
Expand Down Expand Up @@ -323,6 +331,13 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
}
}


inline fun withoutAnalyze(block: (CodeEditor) -> Unit) {
isCodeAnalyzerEnabled = false
block(this)
isCodeAnalyzerEnabled = true
}

private class CodeSyntaxSpan(@ColorInt color: Int) : ForegroundColorSpan(color) // classes to distinct internal spans from non CodeEditor spans
private class CodeHighlightSpan(@ColorInt color: Int) : BackgroundColorSpan(color)
}
Loading

0 comments on commit 899e5a2

Please sign in to comment.