Skip to content

Commit

Permalink
fix news display
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Nov 17, 2017
1 parent 85b21ec commit b94be8c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Habitica/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="1957"
android:versionCode="1958"
android:versionName="1.3"
android:screenOrientation="portrait"
android:installLocation="auto" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.habitrpg.android.habitica.ui.fragments.setup.AvatarSetupFragment;
import com.habitrpg.android.habitica.ui.fragments.setup.IntroFragment;
import com.habitrpg.android.habitica.ui.fragments.setup.TaskSetupFragment;
import com.habitrpg.android.habitica.ui.fragments.setup.WelcomeFragment;
import com.habitrpg.android.habitica.ui.fragments.skills.SkillTasksRecyclerViewFragment;
import com.habitrpg.android.habitica.ui.fragments.skills.SkillsFragment;
import com.habitrpg.android.habitica.ui.fragments.social.ChatListFragment;
Expand Down Expand Up @@ -293,4 +294,6 @@ public interface AppComponent {
void inject(@NotNull BulkAllocateStatsDialog bulkAllocateStatsDialog);

void inject(@NotNull PushNotificationsPreferencesFragment pushNotificationsPreferencesFragment);

void inject(WelcomeFragment welcomeFragment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface TaskRepository : BaseRepository {
fun retrieveTasks(userId: String, tasksOrder: TasksOrder): Observable<TaskList>
fun retrieveTasks(userId: String, tasksOrder: TasksOrder, dueDate: Date): Observable<TaskList>

fun taskChecked(user: User?, task: Task, up: Boolean, force: Boolean): Observable<TaskScoringResult>
fun taskChecked(user: User?, taskId: String, up: Boolean, force: Boolean): Observable<TaskScoringResult>
fun taskChecked(user: User?, task: Task, up: Boolean, force: Boolean): Observable<TaskScoringResult?>
fun taskChecked(user: User?, taskId: String, up: Boolean, force: Boolean): Observable<TaskScoringResult?>
fun scoreChecklistItem(taskId: String, itemId: String): Observable<Task>

fun getTask(taskId: String): Observable<Task>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
.doOnNext { res -> this.localRepository.saveTasks(userId, tasksOrder, res) }
}

override fun taskChecked(user: User?, task: Task, up: Boolean, force: Boolean): Observable<TaskScoringResult> {
override fun taskChecked(user: User?, task: Task, up: Boolean, force: Boolean): Observable<TaskScoringResult?> {
val now = Date().time
if (lastTaskAction > now - 500 && !force) {
return Observable.just(TaskScoringResult())
return Observable.just(null)
}
lastTaskAction = now
return this.apiClient.postTaskDirection(task.id, (if (up) TaskDirection.up else TaskDirection.down).toString())
Expand Down Expand Up @@ -90,7 +90,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
}
}

override fun taskChecked(user: User?, taskId: String, up: Boolean, force: Boolean): Observable<TaskScoringResult> {
override fun taskChecked(user: User?, taskId: String, up: Boolean, force: Boolean): Observable<TaskScoringResult?> {
return localRepository.getTask(taskId).first()
.flatMap { task -> taskChecked(user, task, up, force) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
}

override fun runCron(tasks: List<Task>) {
val observable: Observable<List<TaskScoringResult>> = if (tasks.isNotEmpty()) {
val observable: Observable<List<TaskScoringResult?>> = if (tasks.isNotEmpty()) {
Observable.from(tasks)
.flatMap { task -> taskRepository.taskChecked(null, task, true, true) }
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ public void onTutorialCompleted(TutorialStep step) {

@Override
public void onTutorialDeferred(TutorialStep step) {
step.setDisplayedOn(new Date());
taskRepository.executeTransaction(realm -> step.setDisplayedOn(new Date()));

this.removeActiveTutorialView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class NewsFragment : BaseMainFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
hideToolbar()
return container?.inflate(R.layout.fragment_news)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val address = if (BuildConfig.DEBUG) BuildConfig.BASE_URL else context?.getString(R.string.base_url)
val webSettings = newsWebview.getSettings()
webSettings.setJavaScriptEnabled(true)
val webSettings = newsWebview.settings
webSettings.javaScriptEnabled = true
webSettings.domStorageEnabled = true
newsWebview.webChromeClient = object : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
Log.d("Habitica", consoleMessage.message() + " -- From line "
Expand All @@ -37,6 +39,11 @@ class NewsFragment : BaseMainFragment() {
newsWebview.loadUrl(address + "/static/new-stuff")
}

override fun onDestroyView() {
showToolbar()
super.onDestroyView()
}

override fun injectFragment(component: AppComponent) {
component.inject(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

@Override
public void injectFragment(AppComponent component) {}
public void injectFragment(AppComponent component) {
component.inject(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void onAnimationEnd(Animator animation) {
runBlink();
}
});
animator.start();
try {
animator.start();
} catch (NullPointerException ignored) {
}
}
}

0 comments on commit b94be8c

Please sign in to comment.