Skip to content

Commit

Permalink
[New Designs] Update Dashboard view to match new design (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel authored Dec 5, 2023
1 parent 0bf531c commit 5aac551
Show file tree
Hide file tree
Showing 28 changed files with 710 additions and 448 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: dev-apk
path: app/build/outputs/apk/devFull/release
path: app/build/outputs/apk/devFull/release
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId 'org.openobservatory.ooniprobe'
minSdk libs.versions.minSdk.get().toInteger()
targetSdk libs.versions.targetSdk.get().toInteger()
versionName '3.8.4'
versionCode 106
versionName '3.8.5'
versionCode 107
testInstrumentationRunner "org.openobservatory.ooniprobe.TestAndroidJUnitRunner"
buildConfigField 'String', 'OONI_API_BASE_URL', '"https://api.ooni.io/"'
buildConfigField 'String', 'NOTIFICATION_SERVER', '"https://countly.ooni.io"'
Expand Down Expand Up @@ -149,7 +149,7 @@ dependencies {
// Unit Testing
testImplementation project(':shared-test')
testImplementation libs.junit4
testImplementation libs.androidx.core
testImplementation libs.androidx.test.core
testImplementation libs.androidx.runner
testImplementation libs.androidx.rules
testImplementation libs.mockito.core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

public class MainActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private static final String RES_ITEM = "resItem";
private static final String RES_SNACKBAR_MESSAGE = "resSnackbarMessage";
public static final String NOTIFICATION_DIALOG = "notification";
public static final String AUTOTEST_DIALOG = "automatic_testing";
public static final String BATTERY_DIALOG = "battery_optimization";
Expand All @@ -59,7 +60,14 @@ public static Intent newIntent(Context context, int resItem) {
return new Intent(context, MainActivity.class).putExtra(RES_ITEM, resItem).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

@Override
public static Intent newIntent(Context context, int resItem, String message) {
return new Intent(context, MainActivity.class)
.putExtra(RES_ITEM, resItem)
.putExtra(RES_SNACKBAR_MESSAGE, message)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
Expand All @@ -85,7 +93,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return false;
}
});
/* TODO(aanorbel): Fix change in state(theme change from notification) changes the selected item.
The proper fix would be to track the selected item as well as other properties in a `ViewModel`. */
binding.bottomNavigation.setSelectedItemId(getIntent().getIntExtra(RES_ITEM, R.id.dashboard));
/* Check if we are restoring the activity from a saved state first.
* If we have a message to show, show it as a snackbar.
* This is used to show the message from test completion.
*/
if (savedInstanceState == null && getIntent().hasExtra(RES_SNACKBAR_MESSAGE)) {
Snackbar.make(binding.getRoot(), getIntent().getStringExtra(RES_SNACKBAR_MESSAGE), Snackbar.LENGTH_SHORT)
.setAnchorView(binding.bottomNavigation)
.show();
}
if (notificationManager.shouldShowAutoTest()) {
new ConfirmDialogFragment.Builder()
.withTitle(getString(R.string.Modal_Autorun_Modal_Title))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static Intent newIntent(Context context, AbstractSuite testSuite) {
String experimentalLinks =
"\n\n* [STUN Reachability](https://github.com/ooni/spec/blob/master/nettests/ts-025-stun-reachability.md)" +
"\n\n* [DNS Check](https://github.com/ooni/spec/blob/master/nettests/ts-028-dnscheck.md)" +
"\n\n* [RiseupVPN](https://ooni.org/nettest/riseupvpn/)" +
"\n\n* [ECH Check](https://github.com/ooni/spec/blob/master/nettests/ts-039-echcheck.md)" +
"\n\n* [Tor Snowflake](https://ooni.org/nettest/tor-snowflake/) "+ String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest))+
"\n\n* [Vanilla Tor](https://github.com/ooni/spec/blob/master/nettests/ts-016-vanilla-tor.md) " + String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected void onDestroy() {
}

private void testEnded(Context context) {
startActivity(MainActivity.newIntent(context, R.id.testResults));
startActivity(MainActivity.newIntent(context, R.id.testResults,"Probe Run complete"));
finish();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.openobservatory.ooniprobe.adapters

import android.content.res.Resources
import android.graphics.PorterDuff
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import org.openobservatory.ooniprobe.R
import org.openobservatory.ooniprobe.common.PreferenceManager
import org.openobservatory.ooniprobe.databinding.ItemSeperatorBinding
import org.openobservatory.ooniprobe.databinding.ItemTestsuiteBinding
import org.openobservatory.ooniprobe.test.suite.AbstractSuite

class DashboardAdapter(
private val items: List<Any>,
private val onClickListener: View.OnClickListener,
private val preferenceManager: PreferenceManager,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

companion object {
private const val VIEW_TYPE_TITLE = 0
private const val VIEW_TYPE_CARD = 1
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
VIEW_TYPE_TITLE -> {
CardGroupTitleViewHolder(
ItemSeperatorBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
)
}

else -> {
CardViewHolder(
ItemTestsuiteBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
)
}
}
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val item = items[position]
when (holder.itemViewType) {
VIEW_TYPE_TITLE -> {
val separator = holder as CardGroupTitleViewHolder
separator.binding.root.text = item as String
}

VIEW_TYPE_CARD -> {
val cardHolder = holder as CardViewHolder
if (item is AbstractSuite) {
cardHolder.binding.apply {
title.setText(item.title)
desc.setText(item.cardDesc)
icon.setImageResource(item.icon)
}
holder.itemView.tag = item
if (item.isTestEmpty(preferenceManager)) {
holder.setIsRecyclable(false)
holder.itemView.apply {
elevation = 0f
isClickable = false
}
val resources: Resources = holder.itemView.context.resources
(holder.itemView as CardView).setCardBackgroundColor(resources.getColor(R.color.disabled_test_background))
holder.binding.apply {
title.setTextColor(resources.getColor(R.color.disabled_test_text))
desc.setTextColor(resources.getColor(R.color.disabled_test_text))
icon.setColorFilter(
resources.getColor(R.color.disabled_test_text),
PorterDuff.Mode.SRC_IN
)
}
} else {
holder.itemView.setOnClickListener(onClickListener)
}
}
}
}
}

override fun getItemCount(): Int {
return items.size
}

override fun getItemViewType(position: Int): Int {
return when (items[position]) {
is String -> VIEW_TYPE_TITLE
else -> VIEW_TYPE_CARD
}
}

/**
* ViewHolder for a dashboard item group.
* @param binding
*/
class CardGroupTitleViewHolder(var binding: ItemSeperatorBinding) :
RecyclerView.ViewHolder(binding.root)

/**
* ViewHolder for dashboard item.
* @param binding
*/
class CardViewHolder(var binding: ItemTestsuiteBinding) : RecyclerView.ViewHolder(binding.root)
}

This file was deleted.

Loading

0 comments on commit 5aac551

Please sign in to comment.