Skip to content

Commit

Permalink
Merge branch 'release/1.9_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillMakarov committed Jun 6, 2016
2 parents 95907f7 + e9305b9 commit 5f0ef59
Show file tree
Hide file tree
Showing 29 changed files with 361 additions and 32 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "org.stepic.droid"
minSdkVersion 14
targetSdkVersion 23
versionCode 56
versionName "1.9.1"
versionCode 58
versionName "1.9.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
Expand Down Expand Up @@ -143,7 +143,7 @@ repositories {
mavenCentral()
}
buildscript {
ext.kotlin_version = '1.0.0'
ext.kotlin_version = '1.0.2'
repositories {
mavenCentral()
}
Expand Down
84 changes: 83 additions & 1 deletion app/src/main/java/org/stepic/droid/base/StepBaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,36 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.squareup.otto.Subscribe;

import org.stepic.droid.R;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.model.Lesson;
import org.stepic.droid.model.Step;
import org.stepic.droid.model.Unit;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.view.custom.LatexSupportableWebView;
import org.stepic.droid.web.StepResponse;

import butterknife.Bind;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;

public abstract class StepBaseFragment extends FragmentBase {

@Bind(R.id.text_header)
protected LatexSupportableWebView headerWv;

@Bind(R.id.open_comments_root)
protected View openCommentViewClickable;

@Bind(R.id.open_comments_text)
protected TextView textForComment;

protected Step step;
protected Lesson lesson;
protected Unit unit;
Expand All @@ -34,15 +49,36 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
step.getBlock() != null &&
step.getBlock().getText() != null &&
!step.getBlock().getText().equals("")) {

headerWv.setText(step.getBlock().getText());
headerWv.setVisibility(View.VISIBLE);
} else {
headerWv.setVisibility(View.GONE);
}

updateCommentState();

bus.register(this);
}

private void updateCommentState() {
if (step != null && step.getDiscussion_proxy() != null) {
showComment();
} else {
openCommentViewClickable.setVisibility(View.GONE);
}
}

private void showComment() {
openCommentViewClickable.setVisibility(View.VISIBLE);
openCommentViewClickable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mShell.getScreenProvider().openComments(getContext(), step.getDiscussion_proxy(), step.getId());
}
});
textForComment.setText(MainApplication.getAppContext().getResources().getQuantityString(R.plurals.open_comments, step.getDiscussions_count(), step.getDiscussions_count()));
}


@Override
public void onResume() {
Expand All @@ -53,6 +89,52 @@ public void onResume() {
@Override
public void onDestroyView() {
bus.unregister(this);
openCommentViewClickable.setOnClickListener(null);
super.onDestroyView();
}

@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
if (step != null && event.getTargetId() == step.getId()) {
long[] arr = new long[]{step.getId()};

mShell.getApi().getSteps(arr).enqueue(new Callback<StepResponse>() {
@Override
public void onResponse(Response<StepResponse> response, Retrofit retrofit) {
if (response.isSuccess()) {
StepResponse stepResponse = response.body();
if (stepResponse != null && stepResponse.getSteps() != null && stepResponse.getSteps().size() > 0) {
final Step stepFromInternet = stepResponse.getSteps().get(0);
if (stepFromInternet != null) {
mThreadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
mDatabaseFacade.addStep(stepFromInternet); //fixme: fragment in closure -> leak
}
});

//fixme: it is so bad, we should be updated from model, not here =(
bus.post(new StepWasUpdatedEvent(stepFromInternet));
}
}
}
}

@Override
public void onFailure(Throwable t) {

}
});
}

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event){
if (event.getStep().getId() == step.getId()){
step.setDiscussion_proxy(event.getStep().getDiscussion_proxy()); //fixme do it in immutable way
step.setDiscussions_count(event.getStep().getDiscussions_count());
updateCommentState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package org.stepic.droid.events.comments

import org.stepic.droid.model.comments.Comment

data class NeedReloadCommentsEvent (val targetId : Long, val newCommentInsert: Comment?)
data class NewCommentWasAdded(val targetId : Long, val newCommentInsert: Comment?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.stepic.droid.events.steps;

import org.stepic.droid.model.Step;

public class StepWasUpdatedEvent {
private Step step;

public StepWasUpdatedEvent(Step step) {
this.step = step;
}

public Step getStep() {
return step;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import org.stepic.droid.util.HtmlHelper;

Expand All @@ -30,26 +28,12 @@ public LatexSupportableWebView(Context context, AttributeSet attrs, int defStyle
}

private void init() {
setEnabled(false);
setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
setWebViewClient(new WebViewClient() {
@Override
public void onLoadResource(WebView view, String url) {
view.stopLoading();
}
});
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int i = 0;
return true;
}
});
}

public void setText(CharSequence text) {
Expand All @@ -58,18 +42,14 @@ public void setText(CharSequence text) {
final String encoding = "UTF-8";
setBackgroundColor(0);

// WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
// Display display = wm.getDefaultDisplay();
// Point size = new Point();
// display.getSize(size);
// int width = size.x;

DisplayMetrics displaymetrics = new DisplayMetrics();
((AppCompatActivity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;


getSettings().setDomStorageEnabled(true);
if (text.toString().contains("$")) {
WebSettings webSettings = getSettings();
webSettings.setJavaScriptEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.attempts.FailAttemptEvent;
import org.stepic.droid.events.attempts.SuccessAttemptEvent;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.events.submissions.FailGettingLastSubmissionEvent;
import org.stepic.droid.events.submissions.FailSubmissionCreatedEvent;
import org.stepic.droid.events.submissions.SubmissionCreatedEvent;
Expand Down Expand Up @@ -151,4 +153,15 @@ public void onFailCreateSubmission(FailSubmissionCreatedEvent event) {
public void onFailGettingSubmission(FailGettingLastSubmissionEvent e) {
super.onFailGettingSubmission(e);
}

@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
super.onNewCommentWasAdded(event);

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event) {
super.onStepWasUpdated(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.attempts.FailAttemptEvent;
import org.stepic.droid.events.attempts.SuccessAttemptEvent;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.events.submissions.FailGettingLastSubmissionEvent;
import org.stepic.droid.events.submissions.FailSubmissionCreatedEvent;
import org.stepic.droid.events.submissions.SubmissionCreatedEvent;
Expand Down Expand Up @@ -118,4 +120,15 @@ public void onFailCreateSubmission(FailSubmissionCreatedEvent event) {
public void onFailGettingSubmission(FailGettingLastSubmissionEvent e) {
super.onFailGettingSubmission(e);
}
@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
super.onNewCommentWasAdded(event);

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event) {
super.onStepWasUpdated(event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class CommentsFragment : FragmentBase(), SwipeRefreshLayout.OnRefreshListener {
}

@Subscribe
fun onNeedUpdate(needUpdateEvent: NeedReloadCommentsEvent) {
fun onNeedUpdate(needUpdateEvent: NewCommentWasAdded) {
if (needUpdateEvent.targetId == stepId) {
if (needUpdateEvent.newCommentInsert != null) {
//share for updating:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.attempts.FailAttemptEvent;
import org.stepic.droid.events.attempts.SuccessAttemptEvent;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.events.submissions.FailGettingLastSubmissionEvent;
import org.stepic.droid.events.submissions.FailSubmissionCreatedEvent;
import org.stepic.droid.events.submissions.SubmissionCreatedEvent;
Expand Down Expand Up @@ -116,4 +118,15 @@ public void onFailCreateSubmission(FailSubmissionCreatedEvent event) {
public void onFailGettingSubmission(FailGettingLastSubmissionEvent e) {
super.onFailGettingSubmission(e);
}

@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
super.onNewCommentWasAdded(event);

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event) {
super.onStepWasUpdated(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.attempts.FailAttemptEvent;
import org.stepic.droid.events.attempts.SuccessAttemptEvent;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.events.submissions.FailGettingLastSubmissionEvent;
import org.stepic.droid.events.submissions.FailSubmissionCreatedEvent;
import org.stepic.droid.events.submissions.SubmissionCreatedEvent;
Expand Down Expand Up @@ -228,4 +230,15 @@ public void onFailCreateSubmission(FailSubmissionCreatedEvent event) {
public void onFailGettingSubmission(FailGettingLastSubmissionEvent e) {
super.onFailGettingSubmission(e);
}

@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
super.onNewCommentWasAdded(event);

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event) {
super.onStepWasUpdated(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.attempts.FailAttemptEvent;
import org.stepic.droid.events.attempts.SuccessAttemptEvent;
import org.stepic.droid.events.comments.NewCommentWasAdded;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
import org.stepic.droid.events.submissions.FailGettingLastSubmissionEvent;
import org.stepic.droid.events.submissions.FailSubmissionCreatedEvent;
import org.stepic.droid.events.submissions.SubmissionCreatedEvent;
Expand Down Expand Up @@ -69,4 +71,17 @@ public void onFailCreateSubmission(FailSubmissionCreatedEvent event) {
public void onFailGettingSubmission(FailGettingLastSubmissionEvent e) {
super.onFailGettingSubmission(e);
}

@Subscribe
public void onNewCommentWasAdded(NewCommentWasAdded event) {
super.onNewCommentWasAdded(event);

}

@Subscribe
public void onStepWasUpdated(StepWasUpdatedEvent event) {
super.onStepWasUpdated(event);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.yandex.metrica.YandexMetrica
import org.stepic.droid.R
import org.stepic.droid.base.FragmentBase
import org.stepic.droid.base.MainApplication
import org.stepic.droid.events.comments.NeedReloadCommentsEvent
import org.stepic.droid.events.comments.NewCommentWasAdded
import org.stepic.droid.util.ProgressHelper
import org.stepic.droid.view.custom.LoadingProgressDialog
import org.stepic.droid.web.CommentsResponse
Expand Down Expand Up @@ -149,7 +149,7 @@ class NewCommentFragment : FragmentBase() {
if (response?.isSuccess ?: false && response?.body()?.comments != null) {
YandexMetrica.reportEvent("comments: comment was sent successfully")
val newComment = response?.body()?.comments?.firstOrNull()
bus.post(NeedReloadCommentsEvent(targetId = target!!, newCommentInsert = newComment))
bus.post(NewCommentWasAdded(targetId = target!!, newCommentInsert = newComment))
Toast.makeText(MainApplication.getAppContext(), R.string.comment_sent, Toast.LENGTH_SHORT).show()
onFinishTryingSending()
activity?.finish()
Expand Down
Loading

0 comments on commit 5f0ef59

Please sign in to comment.