Skip to content

Add link to Settings Panel in offline mode #671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions app/src/main/java/io/plaidapp/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.os.Bundle;
import android.provider.Settings;
import android.text.Annotation;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
Expand All @@ -44,6 +45,7 @@
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
Expand All @@ -52,7 +54,9 @@
import android.widget.Toast;
import android.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.core.os.BuildCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentActivity;
Expand All @@ -62,6 +66,7 @@
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
import com.bumptech.glide.util.ViewPreloadSizeProvider;
import com.google.android.material.snackbar.Snackbar;
import io.plaidapp.R;
import io.plaidapp.core.dagger.qualifier.IsPocketInstalled;
import io.plaidapp.core.data.PlaidItem;
Expand Down Expand Up @@ -106,13 +111,15 @@ public class HomeActivity extends FragmentActivity {
private ImageButton fab;
private RecyclerView filtersList;
private ProgressBar loading;
@Nullable private ImageView noConnection;
@Nullable
private ConstraintLayout noConnection;
private ImageButton fabPosting;
private GridLayoutManager layoutManager;
private int columns;
private TextView noFiltersEmptyText;
private FilterAdapter filtersAdapter;
private FeedAdapter adapter;
private Snackbar settingsSnackbar;

// data
@Inject
Expand All @@ -138,7 +145,7 @@ protected void onCreate(Bundle savedInstanceState) {

adapter = new FeedAdapter(this, columns, pocketInstalled);

if(connectivityChecker != null) {
if (connectivityChecker != null) {
getLifecycle().addObserver(connectivityChecker);
connectivityChecker.getConnectedStatus().observe(this, connected -> {
if (connected) {
Expand All @@ -165,7 +172,7 @@ protected void onCreate(Bundle savedInstanceState) {
});

viewModel.getFeedProgress().observe(this, feedProgressUiModel -> {
if(feedProgressUiModel.isLoading()){
if (feedProgressUiModel.isLoading()) {
adapter.dataStartedLoading();
} else {
adapter.dataFinishedLoading();
Expand Down Expand Up @@ -216,12 +223,12 @@ private void bindResources() {
});
filtersList = findViewById(R.id.filters);
loading = findViewById(android.R.id.empty);
noConnection = findViewById(R.id.no_connection);
noConnection = findViewById(R.id.no_connection_holder);

columns = getResources().getInteger(R.integer.num_columns);
}

private void setupGrid(){
private void setupGrid() {
grid.setAdapter(adapter);
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
Expand Down Expand Up @@ -259,7 +266,7 @@ public boolean isDataLoading() {
grid.addOnScrollListener(shotPreloader);
}

private void handleDrawerInsets(WindowInsets insets){
private void handleDrawerInsets(WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar
.getLayoutParams();
Expand Down Expand Up @@ -462,7 +469,6 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
};



protected void fabClick() {
if (viewModel.isDesignerNewsUserLoggedIn()) {
Intent intent = ActivityHelper.intentTo(Activities.DesignerNews.PostStory.INSTANCE);
Expand Down Expand Up @@ -697,10 +703,10 @@ private void showFab() {

/**
* Highlight the new source(s) by:
* 1. opening the drawer
* 2. scrolling new source(s) into view
* 3. flashing new source(s) background
* 4. closing the drawer (if user hasn't interacted with it)
* 1. opening the drawer
* 2. scrolling new source(s) into view
* 3. flashing new source(s) background
* 4. closing the drawer (if user hasn't interacted with it)
*/
private void highlightPosition(SourcesHighlightUiModel uiModel) {
final Runnable closeDrawerRunnable = () -> drawer.closeDrawer(GravityCompat.END);
Expand Down Expand Up @@ -746,21 +752,31 @@ private void handleNoNetworkConnection() {
loading.setVisibility(View.GONE);
if (noConnection == null) {
final ViewStub stub = findViewById(R.id.stub_no_connection);
noConnection = (ImageView) stub.inflate();
noConnection = (ConstraintLayout) stub.inflate();
}
final AnimatedVectorDrawable avd =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
if (noConnection != null && avd != null) {
noConnection.setImageDrawable(avd);
ImageView imageView = noConnection.findViewById(R.id.no_connection);
imageView.setImageDrawable(avd);
avd.start();

Button settingsButton = noConnection.findViewById(R.id.no_connection_button);
settingsButton.setOnClickListener(v -> {
if (BuildCompat.isAtLeastQ()) {
startActivity(new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY));
} else {
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
});
}
}

private void handleNetworkConnected() {
if (adapter.getDataItemCount() != 0) return;

TransitionManager.beginDelayedTransition(drawer);
if(noConnection != null) {
if (noConnection != null) {
noConnection.setVisibility(View.GONE);
}
loading.setVisibility(View.VISIBLE);
Expand Down
52 changes: 45 additions & 7 deletions app/src/main/res/layout/no_connection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,49 @@
See the License for the specific language governing permissions and
limitations under the License.
-->

<ImageView
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/no_connection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="?android:actionBarSize"
android:src="@drawable/no_connection" />
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/no_connection_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="100dp">

<ImageView
android:id="@+id/no_connection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/spacing_large"
android:src="@drawable/no_connection"
android:contentDescription="@string/no_connectivity_content_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<io.plaidapp.core.ui.widget.BaselineGridTextView
android:id="@+id/no_connection_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/padding_normal"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.EmptyText"
android:text="@string/no_connectivity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/no_connection" />

<Button
style="?android:borderlessButtonStyle"
android:id="@+id/no_connection_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding_normal"
android:text="@string/network_settings"
android:textColor="?android:attr/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/no_connection_text" />

</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -38,4 +39,9 @@
<!--searchable label-->
<string name="search_hint">Search Dribbble &amp; Designer News</string>

<!--connectivity-->
<string name="no_connectivity">Your network is unavailable.\nCheck your data or wifi connection.</string>
<string name="no_connectivity_content_description">Your network is unavailable</string>
<string name="network_settings">Network Settings</string>

</resources>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ buildscript { scriptHandler ->
apply from: 'repositories.gradle',
to: scriptHandler
ext.versions = [
'compileSdk' : 28,
'compileSdk' : 'android-Q',
'minSdk' : 23,
'targetSdk' : 28,
'targetSdk' : 29,
'androidx' : '1.0.0',
'androidxCollection' : '1.0.0',
'androidxCoreRuntime': '2.0.1-alpha01',
Expand Down