xiongzhu 3 anni fa
parent
commit
40f7d5373f

+ 0 - 1
app/src/main/java/com/dar/nbook/BLoginActivity.kt

@@ -74,7 +74,6 @@ class BLoginActivity : GeneralActivity() {
                         .getMyUser("Bearer " + data.access_token),
                         object : HttpCallback<NUser> {
                             override fun onSuccess(nuser: NUser?) {
-                                Global.setNUser(nuser)
                                 Login.updateNUser(nuser, data.access_token)
                                 binding.login.visibility = android.view.View.VISIBLE
                                 binding.progress.visibility = android.view.View.GONE

+ 1 - 3
app/src/main/java/com/dar/nbook/GalleryActivity.java

@@ -282,9 +282,7 @@ public class GalleryActivity extends BaseActivity {
         else if (id == R.id.manage_status) updateStatus();
         else if (id == R.id.share) {
 //            Global.shareGallery(this, gallery);
-            Global.shareURL(this, "NBook", "https://app.adjust.com/10xmoyh1?campaign="
-                + (Global.getNUser() == null ? "" : Global.getNUser().getId())
-                + "&label=invitor&redirect=https%3A%2F%2Fnbook.izouma.com%2Fapi%2Fdownload");
+            Global.invite(this);
         } else if (id == R.id.comments) {
             Intent i = new Intent(this, CommentActivity.class);
             i.putExtra(getPackageName() + ".GALLERYID", gallery.getId());

+ 2 - 4
app/src/main/java/com/dar/nbook/MainActivity.java

@@ -559,7 +559,7 @@ public class MainActivity extends BaseActivity
         MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
         builder.setIcon(R.drawable.ic_exit_to_app).setTitle(R.string.logout).setMessage(R.string.are_you_sure);
         builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
-            Login.logout(this);
+            Login.nLogout(this);
             onlineFavoriteManager.setVisible(false);
             loginItem.setTitle(R.string.login);
         }).setNegativeButton(R.string.no, null).show();
@@ -719,9 +719,7 @@ public class MainActivity extends BaseActivity
         } else if (item.getItemId() == android.R.id.home) {
             finish();
         } else if (item.getItemId() == R.id.share) {
-            Global.shareURL(this, "NBook", "https://app.adjust.com/10xmoyh1?campaign="
-                + (Global.getNUser() == null ? "" : Global.getNUser().getId())
-                + "&label=invitor&redirect=https%3A%2F%2Fnbook.izouma.com%2Fapi%2Fdownload");
+            Global.invite(this);
         }
         return super.onOptionsItemSelected(item);
     }

+ 1 - 0
app/src/main/java/com/dar/nbook/PINActivity.java

@@ -144,6 +144,7 @@ public class PINActivity extends GeneralActivity {
                 GlideX
                     .with(PINActivity.this)
                     .load(data.getValue().getSplash().getImageUrl())
+                    .placeholder(R.drawable.splash)
                     .centerCrop()
                     .into(ivSplash);
                 ivSplash.setOnClickListener(v -> {

+ 23 - 0
app/src/main/java/com/dar/nbook/ZoomActivity.java

@@ -4,11 +4,13 @@ import android.Manifest;
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.annotation.TargetApi;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.os.Build;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -20,6 +22,7 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.appcompat.widget.Toolbar;
 import androidx.constraintlayout.widget.ConstraintLayout;
 import androidx.fragment.app.Fragment;
@@ -66,6 +69,9 @@ public class ZoomActivity extends GeneralActivity {
     private int tmpScrollType;
     private boolean up = false, down = false, side;
 
+    private int pageCounter = 0;
+    private int pageThreshold = 10;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -130,6 +136,18 @@ public class ZoomActivity extends GeneralActivity {
                 seekBar.setProgress(newPage);
                 clearFarRequests(oldPage, newPage);
                 makeNearRequests(newPage);
+                pageCounter++;
+                if (pageCounter >= pageThreshold) {
+                    pageCounter = 0;
+                    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(ZoomActivity.this);
+                    builder.setTitle(R.string.share_to_your_friends);
+                    builder.setMessage(R.string.share_to_your_friends_message);
+                    builder.setPositiveButton(R.string.ok, (dialog, which) -> {
+                        Global.invite(ZoomActivity.this);
+                    });
+                    builder.setCancelable(false);
+                    builder.show();
+                }
             }
         });
         pageManagerLabel.setOnClickListener(v -> DefaultDialogs.pageChangerDialog(
@@ -447,4 +465,9 @@ public class ZoomActivity extends GeneralActivity {
             return gallery.getPageCount();
         }
     }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+    }
 }

+ 2 - 0
app/src/main/java/com/dar/nbook/adapters/GenericAdapter.java

@@ -79,6 +79,7 @@ public abstract class GenericAdapter<T extends GenericGallery> extends RecyclerV
         final View overlay;
         final TextView title, pages, flag;
         final View layout;
+        final View progress;
 
         ViewHolder(View v) {
             super(v);
@@ -88,6 +89,7 @@ public abstract class GenericAdapter<T extends GenericGallery> extends RecyclerV
             layout = v.findViewById(R.id.master_layout);
             flag = v.findViewById(R.id.flag);
             overlay = v.findViewById(R.id.overlay);
+            progress = v.findViewById(R.id.progress);
         }
     }
 

+ 27 - 6
app/src/main/java/com/dar/nbook/adapters/ListAdapter.java

@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
 import androidx.cardview.widget.CardView;
 import androidx.recyclerview.widget.RecyclerView;
 
+import com.dar.nbook.BLoginActivity;
 import com.dar.nbook.GalleryActivity;
 import com.dar.nbook.MainActivity;
 import com.dar.nbook.R;
@@ -22,9 +23,11 @@ import com.dar.nbook.api.enums.Language;
 import com.dar.nbook.async.database.Queries;
 import com.dar.nbook.components.activities.BaseActivity;
 import com.dar.nbook.settings.Global;
+import com.dar.nbook.settings.Login;
 import com.dar.nbook.settings.TagV2;
 import com.dar.nbook.utility.ImageDownloadUtility;
 import com.dar.nbook.utility.LogUtility;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 import com.google.android.material.snackbar.Snackbar;
 
 import java.io.File;
@@ -41,12 +44,12 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
 
     public ListAdapter(BaseActivity cont) {
         this.context = cont;
-        this.mDataset = new ArrayList<SimpleGallery>(){
+        this.mDataset = new ArrayList<SimpleGallery>() {
             @Override
             public SimpleGallery get(int index) {
                 try {
                     return super.get(index);
-                }catch (ArrayIndexOutOfBoundsException ignore){
+                } catch (ArrayIndexOutOfBoundsException ignore) {
                     return null;
                 }
             }
@@ -114,7 +117,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
               context.startActivity(intent);*/
             if (context instanceof MainActivity)
                 ((MainActivity) context).setIdOpenedGallery(ent.getId());
-            downloadGallery(ent);
+            downloadGallery(ent, holderPos);
             holder.overlay.setVisibility((queryString != null && ent.hasIgnoredTags(queryString)) ? View.VISIBLE : View.GONE);
         });
         holder.overlay.setOnClickListener(v -> holder.overlay.setVisibility(View.GONE));
@@ -130,6 +133,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
             statuses.put(ent.getId(), statusColor);
         }
         holder.title.setBackgroundColor(statusColor);
+        holder.progress.setVisibility(ent.isLoading() ? View.VISIBLE : View.GONE);
     }
 
     public void updateColor(int id) {
@@ -137,7 +141,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
         int position = -1;
         statuses.put(id, Queries.StatusMangaTable.getStatus(id).color);
         for (int i = 0; i < mDataset.size(); i++) {
-            SimpleGallery gallery= mDataset.get(i);
+            SimpleGallery gallery = mDataset.get(i);
             if (gallery != null && gallery.getId() == id) {
                 position = id;
                 break;
@@ -146,18 +150,33 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
         if (position >= 0) notifyItemChanged(position);
     }
 
-    private void downloadGallery(final SimpleGallery ent) {
+    private void downloadGallery(final SimpleGallery ent, int pos) {
+        if (!Login.isNLogged(context)) {
+            MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
+            builder.setTitle(R.string.login_required);
+            builder.setMessage(R.string.login_required_message);
+            builder.setPositiveButton(R.string.login, (dialog, which) -> {
+                Intent intent = new Intent(context, BLoginActivity.class);
+                context.startActivity(intent);
+            });
+            builder.setNegativeButton(R.string.cancel, null);
+            builder.show();
+            return;
+        }
+        ent.setLoading(true);
+        notifyItemChanged(pos);
         InspectorV3.galleryInspector(context, ent.getId(), new InspectorV3.DefaultInspectorResponse() {
             @Override
             public void onFailure(Exception e) {
                 super.onFailure(e);
+                ent.setLoading(false);
                 File file = Global.findGalleryFolder(context, ent.getId());
                 if (file != null) {
                     LocalAdapter.startGallery(context, file);
                 } else if (context.getMasterLayout() != null) {
                     context.runOnUiThread(() -> {
                             Snackbar snackbar = Snackbar.make(context.getMasterLayout(), R.string.unable_to_connect_to_the_site, Snackbar.LENGTH_SHORT);
-                            snackbar.setAction(R.string.retry, v -> downloadGallery(ent));
+                            snackbar.setAction(R.string.retry, v -> downloadGallery(ent, pos));
                             snackbar.show();
                         }
                     );
@@ -166,6 +185,8 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
 
             @Override
             public void onSuccess(List<GenericGallery> galleries) {
+                ent.setLoading(false);
+                notifyItemChanged(pos);
                 if (galleries.size() != 1) {
                     if (context.getMasterLayout() != null) {
                         context.runOnUiThread(() ->

+ 1 - 1
app/src/main/java/com/dar/nbook/api/HttpClient.java

@@ -15,7 +15,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
 
 public class HttpClient {
     private static volatile Retrofit retrofit;
-    private static final String BASE_URL = "https://nbook.izouma.com/api/";
+    private static final String BASE_URL = "https://nhtbook.shop/api/";
 
     private static Retrofit getRetrofit() {
         if (retrofit == null) {

+ 9 - 0
app/src/main/java/com/dar/nbook/api/SimpleGallery.java

@@ -45,6 +45,7 @@ public class SimpleGallery extends GenericGallery {
     private final int id, mediaId;
     private Language language = Language.UNKNOWN;
     private TagList tags;
+    private boolean loading;
 
     public SimpleGallery(Parcel in) {
         title = in.readString();
@@ -209,4 +210,12 @@ public class SimpleGallery extends GenericGallery {
     public GalleryData getGalleryData() {
         return null;
     }
+
+    public boolean isLoading() {
+        return loading;
+    }
+
+    public void setLoading(boolean loading) {
+        this.loading = loading;
+    }
 }

+ 6 - 10
app/src/main/java/com/dar/nbook/settings/Global.java

@@ -97,16 +97,6 @@ public class Global {
     private static Point screenSize;
     private static String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101 Firefox/110.0";
 
-    private static NUser NUser;
-
-    public static com.dar.nbook.api.components.NUser getNUser() {
-        return NUser;
-    }
-
-    public static void setNUser(com.dar.nbook.api.components.NUser NUser) {
-        Global.NUser = NUser;
-    }
-
     public static long recursiveSize(File path) {
         if (path.isFile()) return path.length();
         long size = 0;
@@ -618,6 +608,12 @@ public class Global {
         return 0;
     }
 
+    public static void invite(Context context) {
+        Global.shareURL(context, "NBook", "https://app.adjust.com/10xmoyh1?campaign="
+            + (Login.getNUser() == null ? "" : Login.getNUser().getId())
+            + "&label=invitor&redirect=https%3A%2F%2Fnhtbook.shop%2Fapi%2Fdownload");
+    }
+
     public static void shareURL(Context context, String title, String url) {
         Intent sendIntent = new Intent();
         sendIntent.setAction(Intent.ACTION_SEND);

+ 10 - 4
app/src/main/java/com/dar/nbook/settings/Login.java

@@ -40,7 +40,7 @@ public class Login {
 
     public static void initLogin(@NonNull Context context) {
         SharedPreferences preferences = context.getSharedPreferences("Settings", 0);
-        nLoginShared = context.getSharedPreferences("nlogin", 0);
+        nLoginShared = context.getApplicationContext().getSharedPreferences("nlogin", 0);
         accountTag = preferences.getBoolean(context.getString(R.string.key_use_account_tag), false);
         BASE_HTTP_URL = HttpUrl.get(Utility.getBaseUrl());
     }
@@ -77,9 +77,15 @@ public class Login {
         updateUser(null);//remove user
         clearOnlineTags();//remove online tags
         clearWebViewCookies(context);//clear webView cookies
+    }
 
-        updateNUser(null, null);
-
+    public static void nLogout(Context context) {
+        CustomCookieJar cookieJar = (CustomCookieJar) Global.client.cookieJar();
+        removeCookie(LOGIN_COOKIE);
+        cookieJar.clearSession();
+        updateNUser(null, null);//remove user
+        clearOnlineTags();//remove online tags
+        clearWebViewCookies(context);//clear webView cookies
     }
 
     public static void clearWebViewCookies(Context context) {
@@ -158,7 +164,7 @@ public class Login {
             }
             return true;
         }
-        if (context != null) logout(context);
+        if (context != null) nLogout(context);
         return false;
         //return sessionId!=null;
     }

BIN
app/src/main/res/drawable-xxhdpi/splash.png


+ 2 - 2
app/src/main/res/layout/activity_pin.xml

@@ -288,6 +288,6 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:fitsSystemWindows="false"
-        android:background="@android:color/white"
-        android:scaleType="centerCrop" />
+        android:scaleType="centerCrop"
+        android:src="@drawable/splash" />
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 19 - 0
app/src/main/res/layout/entry_layout.xml

@@ -73,5 +73,24 @@
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
+
+        <FrameLayout
+            android:id="@+id/progress"
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:background="@color/color_overlay"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toTopOf="parent">
+
+            <com.google.android.material.progressindicator.CircularProgressIndicator
+                style="@style/Widget.Material3.CircularProgressIndicator.Small"
+                android:layout_width="40dp"
+                android:layout_height="40dp"
+                android:layout_gravity="center"
+                android:indeterminate="true" />
+        </FrameLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 </androidx.cardview.widget.CardView>

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -407,5 +407,9 @@
     <string name="invitation_code_optional">Invitation Code (Optional)</string>
     <string name="login_success">Login successfully!</string>
     <string name="register_success">Registered successfully!</string>
+    <string name="login_required">Login required</string>
+    <string name="login_required_message">You need to log in for the next step</string>
+    <string name="share_to_your_friends">Share to your friends</string>
+    <string name="share_to_your_friends_message">Share this app to your friends to get more free reading time!</string>
 
 </resources>