forked from oppia/oppia-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ia#3376) * Implement Developer Options Starter * Fix lint issues * Implement Developer Options Menu Item in Nav Drawer * Fix lint issues * Added Kdoc. abstract class -> interface * Added tests for Developer Options menu item * Fixed lint issues * Introduced ApplicationComponentForDevMode * Added KDocs and fixed lint issues * Added test to check unavailibility of Dev Options menu item when not in dev mode * Added initial test for DeveloperOptionsActivity. Added KDocs. Fixed lint issues * Introduced DebugApplicationComponent * Implement developer options menu ui * Modified way of passing data to recycler view * removed unnecessary isMultipane boolean * added view models to app/BUILD.bazel * Added tests for DeveloperOptionsActivityTest * Fixed lint issues * Corrected key mismatch error. Changed isDevMode to isDebugMode. Nit fixes * Fixed Robolectric test for NavigationDrawerActivityTest * Updated developer_options_fragment layout * Added test for hints switch * Added eof. Changed dev mode to debug mode * Removed unnecessary lastLoadedFragment flag * Corrected imports * Removed unnecessary code from DeveloperOptionsActivityTest * Modified approach for Application Components * nit fix * nit fix * Added tests and Kdocs + nit fixes * Code reformating * Separated dev and prod tests for NavigationDrawerActivityTest * nit fix * Implemented View Event Logs feature * Added deps to app/BUILD.bazel * Renamed NavigationDrawerActivityDevTest to NavigationDrawerActivityDebugTest * Created DebugLoggerModule * Added deps for debug logging module * Fixed event logs list * Moved starter to devoptions * Moved starter to devoptions * nit fix * Added tests for ViewEventLogsActivity * Added TODOs * Removed unnecessary code. Nit fixes * Nit fixes in ViewEventLogsActivityTest * Added accessiblity test rule. Modified UI for the same * Nit fix * Nit fixes * Fixed bazel lint error * Added TODO * Added Kdoc to DeveloperOptionsViewModel * Removed DebugExceptionLogger * Added KDocs * Code refactoring + added KDocs + nit fixes * Nit changes in strings.xml * KDocs added and updated * fixed bazel build error * Added test to check for intent * Nit fixes * Added TODOs and updated Kdocs * Moved debug_module to firebase package * Nit fix * Added configChange Test * Nit fixes * Fixed ViewEventLogsActivityTest * Nit fixes * Nit + added configChange tests * Fixed ViewEventLogsActivityTest * Test name
- Loading branch information
1 parent
9abd017
commit ef83fde
Showing
27 changed files
with
1,233 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/oppia/android/app/devoptions/RouteToViewEventLogsListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.oppia.android.app.devoptions | ||
|
||
/** Listener for when the user wants to view event logs. */ | ||
interface RouteToViewEventLogsListener { | ||
/** Called when the user indicates that they want to view event logs. */ | ||
fun routeToViewEventLogs() | ||
} |
11 changes: 10 additions & 1 deletion
11
...oppia/android/app/devoptions/devoptionsitemviewmodel/DeveloperOptionsViewLogsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
package org.oppia.android.app.devoptions.devoptionsitemviewmodel | ||
|
||
import org.oppia.android.app.devoptions.RouteToViewEventLogsListener | ||
|
||
/** [DeveloperOptionsItemViewModel] to provide features to view logs such as analytic event logs. */ | ||
class DeveloperOptionsViewLogsViewModel : DeveloperOptionsItemViewModel() | ||
class DeveloperOptionsViewLogsViewModel( | ||
private val routeToViewEventLogsListener: RouteToViewEventLogsListener | ||
) : DeveloperOptionsItemViewModel() { | ||
/** Routes the user to [ViewEventLogsActivity] for displaying the event logs. */ | ||
fun onEventLogsClicked() { | ||
routeToViewEventLogsListener.routeToViewEventLogs() | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/EventLogItemViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import org.oppia.android.app.model.EventLog | ||
import org.oppia.android.app.viewmodel.ObservableViewModel | ||
import org.oppia.android.util.system.OppiaDateTimeFormatter | ||
import javax.inject.Inject | ||
|
||
/** [ViewModel] for displaying a event log. */ | ||
class EventLogItemViewModel @Inject constructor( | ||
val eventLog: EventLog, | ||
private val oppiaDateTimeFormatter: OppiaDateTimeFormatter | ||
) : ObservableViewModel() { | ||
|
||
/** Returns the event log timestamp in a human readable format. */ | ||
fun processDateAndTime(): String { | ||
return oppiaDateTimeFormatter.formatDateFromDateString( | ||
OppiaDateTimeFormatter.DD_MMM_hh_mm_aa, | ||
eventLog.timestamp | ||
) | ||
} | ||
|
||
/** Returns the event log priority in a human readable format. */ | ||
fun formatPriorityString(): String? = eventLog.priority.name.toLowerCase().capitalize() | ||
|
||
/** Returns the event log context in a human readable format. */ | ||
fun formatContextString(): String? = | ||
eventLog.context.activityContextCase.name.capitalizeWords().substringBeforeLast(" ") | ||
|
||
/** Returns the event log action name in a human readable format. */ | ||
fun formatActionNameString(): String = eventLog.actionName.name.capitalizeWords() | ||
|
||
private fun String.capitalizeWords(): String = | ||
toLowerCase().split("_").joinToString(" ") { it.capitalize() } | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import org.oppia.android.R | ||
import org.oppia.android.app.activity.InjectableAppCompatActivity | ||
import javax.inject.Inject | ||
|
||
/** Activity for View Event Logs. */ | ||
class ViewEventLogsActivity : InjectableAppCompatActivity() { | ||
@Inject | ||
lateinit var viewEventLogsActivityPresenter: ViewEventLogsActivityPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
activityComponent.inject(this) | ||
viewEventLogsActivityPresenter.handleOnCreate() | ||
title = getString(R.string.view_event_logs_activity_title) | ||
} | ||
|
||
companion object { | ||
fun createViewEventLogsActivityIntent(context: Context): Intent { | ||
return Intent(context, ViewEventLogsActivity::class.java) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ain/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsActivityPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import org.oppia.android.R | ||
import org.oppia.android.app.activity.ActivityScope | ||
import javax.inject.Inject | ||
|
||
/** The presenter for [ViewEventLogsActivity]. */ | ||
@ActivityScope | ||
class ViewEventLogsActivityPresenter @Inject constructor( | ||
private val activity: AppCompatActivity | ||
) { | ||
|
||
fun handleOnCreate() { | ||
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) | ||
activity.setContentView(R.layout.view_event_logs_activity) | ||
|
||
if (getViewEventLogsFragment() == null) { | ||
val viewEventLogsFragment = ViewEventLogsFragment | ||
.newInstance() | ||
activity.supportFragmentManager.beginTransaction().add( | ||
R.id.view_event_logs_container, | ||
viewEventLogsFragment | ||
).commitNow() | ||
} | ||
} | ||
|
||
private fun getViewEventLogsFragment(): ViewEventLogsFragment? { | ||
return activity.supportFragmentManager | ||
.findFragmentById(R.id.view_event_logs_container) as ViewEventLogsFragment? | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.oppia.android.app.fragment.InjectableFragment | ||
import javax.inject.Inject | ||
|
||
/** Fragment to display all event logs. */ | ||
class ViewEventLogsFragment : InjectableFragment() { | ||
@Inject | ||
lateinit var viewEventLogsFragmentPresenter: ViewEventLogsFragmentPresenter | ||
|
||
companion object { | ||
fun newInstance(): ViewEventLogsFragment { | ||
return ViewEventLogsFragment() | ||
} | ||
} | ||
|
||
override fun onAttach(context: Context) { | ||
super.onAttach(context) | ||
fragmentComponent.inject(this) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return viewEventLogsFragmentPresenter.handleCreateView(inflater, container) | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ain/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragmentPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import org.oppia.android.app.fragment.FragmentScope | ||
import org.oppia.android.app.recyclerview.BindableAdapter | ||
import org.oppia.android.app.viewmodel.ViewModelProvider | ||
import org.oppia.android.databinding.ViewEventLogsEventLogItemViewBinding | ||
import org.oppia.android.databinding.ViewEventLogsFragmentBinding | ||
import javax.inject.Inject | ||
|
||
/** The presenter for [ViewEventLogsFragment]. */ | ||
@FragmentScope | ||
class ViewEventLogsFragmentPresenter @Inject constructor( | ||
private val activity: AppCompatActivity, | ||
private val fragment: Fragment, | ||
private val viewModelProvider: ViewModelProvider<ViewEventLogsViewModel> | ||
) { | ||
|
||
private lateinit var binding: ViewEventLogsFragmentBinding | ||
private lateinit var linearLayoutManager: LinearLayoutManager | ||
private lateinit var bindingAdapter: BindableAdapter<EventLogItemViewModel> | ||
|
||
fun handleCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup? | ||
): View? { | ||
binding = ViewEventLogsFragmentBinding.inflate( | ||
inflater, | ||
container, | ||
/* attachToRoot= */ false | ||
) | ||
|
||
binding.viewEventLogsToolbar.setNavigationOnClickListener { | ||
(activity as ViewEventLogsActivity).finish() | ||
} | ||
|
||
binding.apply { | ||
this.lifecycleOwner = fragment | ||
this.viewModel = getViewEventLogsViewModel() | ||
} | ||
|
||
linearLayoutManager = LinearLayoutManager(activity.applicationContext) | ||
|
||
bindingAdapter = createRecyclerViewAdapter() | ||
binding.viewEventLogsRecyclerView.apply { | ||
layoutManager = linearLayoutManager | ||
adapter = bindingAdapter | ||
} | ||
|
||
return binding.root | ||
} | ||
|
||
private fun createRecyclerViewAdapter(): BindableAdapter<EventLogItemViewModel> { | ||
return BindableAdapter.SingleTypeBuilder | ||
.newBuilder<EventLogItemViewModel>() | ||
.registerViewDataBinderWithSameModelType( | ||
inflateDataBinding = ViewEventLogsEventLogItemViewBinding::inflate, | ||
setViewModel = ViewEventLogsEventLogItemViewBinding::setViewModel | ||
) | ||
.build() | ||
} | ||
|
||
private fun getViewEventLogsViewModel(): ViewEventLogsViewModel { | ||
return viewModelProvider.getForFragment(fragment, ViewEventLogsViewModel::class.java) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.oppia.android.app.devoptions.vieweventlogs | ||
|
||
import org.oppia.android.app.fragment.FragmentScope | ||
import org.oppia.android.app.viewmodel.ObservableViewModel | ||
import org.oppia.android.util.logging.firebase.DebugEventLogger | ||
import org.oppia.android.util.system.OppiaDateTimeFormatter | ||
import javax.inject.Inject | ||
|
||
/** | ||
* [ViewModel] for [ViewEventLogsFragment]. It populates the recyclerview with a list of | ||
* [EventLogItemViewModel] which in turn display the event log. | ||
*/ | ||
@FragmentScope | ||
class ViewEventLogsViewModel @Inject constructor( | ||
debugEventLogger: DebugEventLogger, | ||
private val oppiaDateTimeFormatter: OppiaDateTimeFormatter | ||
) : ObservableViewModel() { | ||
|
||
private val eventList = debugEventLogger.getEventList() | ||
|
||
/** | ||
* List of [EventLogItemViewModel] used to populate recyclerview of [ViewEventLogsFragment] | ||
* to display event logs. | ||
*/ | ||
val eventLogsList: List<EventLogItemViewModel> by lazy { | ||
processEventLogsList() | ||
} | ||
|
||
private fun processEventLogsList(): List<EventLogItemViewModel> { | ||
return eventList.map { | ||
EventLogItemViewModel(it, oppiaDateTimeFormatter) | ||
}.reversed() | ||
} | ||
} |
Oops, something went wrong.