xiongzhu 2 年之前
父節點
當前提交
48b81a3ecb

+ 2 - 6
app/src/main/AndroidManifest.xml

@@ -36,18 +36,14 @@
         android:roundIcon="@mipmap/ic_launcher"
         android:supportsRtl="true"
         android:theme="@style/DarkTheme"
-        android:usesCleartextTraffic="true">
+        android:usesCleartextTraffic="true"
+        android:networkSecurityConfig="@xml/network_security_config">
         <activity
             android:name=".RegisterActivity"
             android:exported="false" />
         <activity
             android:name=".BLoginActivity"
             android:exported="false" />
-        <activity
-            android:name=".NLoginActivity"
-            android:exported="false"
-            android:label="@string/title_activity_nlogin"
-            android:theme="@style/DarkTheme" />
         <activity android:name=".StatusManagerActivity" />
         <activity
             android:name=".PINActivity"

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

@@ -49,6 +49,7 @@ class BLoginActivity : GeneralActivity() {
             }
             login(username, password)
         }
+
     }
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {

+ 30 - 6
app/src/main/java/com/dar/nbook/MainActivity.java

@@ -10,6 +10,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.Message;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -50,7 +51,9 @@ import com.dar.nbook.api.enums.TagStatus;
 import com.dar.nbook.api.enums.TagType;
 import com.dar.nbook.api.request.UserLogin;
 import com.dar.nbook.api.request.UserRegister;
+import com.dar.nbook.api.response.AppConfig;
 import com.dar.nbook.api.response.LoginResponse;
+import com.dar.nbook.api.response.SysConfigResponse;
 import com.dar.nbook.async.ScrapeTags;
 import com.dar.nbook.async.VersionChecker;
 import com.dar.nbook.async.database.Queries;
@@ -70,6 +73,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 import com.google.android.material.navigation.NavigationView;
 import com.google.android.material.snackbar.Snackbar;
 
+import org.jsoup.internal.StringUtil;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -194,12 +199,31 @@ public class MainActivity extends BaseActivity
 
 
         ImageView ivAd = findViewById(R.id.iv_ad);
-        GlideX
-            .with(this)
-            .load("https://paimaide.s3.ap-northeast-1.amazonaws.com/image/2023-03-29-11-25-40mVDVAMUg.png")
-            .centerCrop()
-            .placeholder(R.drawable.ic_logo)
-            .into(ivAd);
+        HttpClient.request(HttpClient.getApiService().getAppConfig(), new HttpCallback<>() {
+            @Override
+            public void onSuccess(SysConfigResponse<AppConfig> data) {
+                if (!StringUtil.isBlank(data.getValue().getBanner().getImageUrl())) {
+                    if (isDestroyed()) return;
+                    ivAd.setVisibility(View.VISIBLE);
+                    GlideX
+                        .with(MainActivity.this)
+                        .load(data.getValue().getBanner().getImageUrl())
+                        .centerCrop()
+                        .placeholder(R.drawable.ic_logo)
+                        .into(ivAd);
+                    ivAd.setOnClickListener(v -> {
+                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data.getValue().getBanner().getUrl()));
+                        startActivity(browserIntent);
+                    });
+                }
+            }
+
+            @Override
+            public void onFailure(HttpError<SysConfigResponse<AppConfig>> error) {
+
+            }
+        });
+
     }
 
     private void manageDrawer() {

+ 0 - 69
app/src/main/java/com/dar/nbook/NLoginActivity.kt

@@ -1,69 +0,0 @@
-@file:OptIn(ExperimentalMaterial3Api::class)
-
-package com.dar.nbook
-
-import android.os.Bundle
-import androidx.activity.ComponentActivity
-import androidx.activity.compose.setContent
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TextField
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.tooling.preview.Preview
-import com.dar.nbook.settings.Global
-import com.dar.nbook.ui.theme.NClientV2Theme
-
-class NLoginActivity : ComponentActivity() {
-
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
-        setContent {
-            NClientV2Theme(darkTheme = Global.getTheme() == Global.ThemeScheme.DARK) {
-                // A surface container using the 'background' color from the theme
-                Surface(
-                    modifier = Modifier.fillMaxSize(),
-                    color = MaterialTheme.colorScheme.background
-                ) {
-                    Login()
-                }
-            }
-        }
-    }
-}
-
-@Composable
-fun Greeting(name: String, modifier: Modifier = Modifier) {
-    Text(
-        text = "Hello $name!",
-        modifier = modifier
-    )
-}
-
-@Composable
-fun Login() {
-    var username by remember { mutableStateOf("Hello") }
-    Column {
-        TextField(
-            value = username,
-            onValueChange = { username = it },
-            label = { Text("Label") }
-        )
-    }
-}
-
-@Preview(showBackground = true)
-@Composable
-fun GreetingPreview() {
-    NClientV2Theme {
-        Login()
-    }
-}

+ 2 - 12
app/src/main/java/com/dar/nbook/PINActivity.java

@@ -140,21 +140,11 @@ public class PINActivity extends GeneralActivity {
         HttpClient.request(HttpClient.getApiService().getAppConfig(), new HttpCallback<>() {
             @Override
             public void onSuccess(SysConfigResponse<AppConfig> data) {
+                if (isDestroyed()) return;
                 GlideX
                     .with(PINActivity.this)
                     .load(data.getValue().getSplash().getImageUrl())
                     .centerCrop()
-                    .addListener(new RequestListener<>() {
-                        @Override
-                        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
-                            return false;
-                        }
-
-                        @Override
-                        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
-                            return false;
-                        }
-                    })
                     .into(ivSplash);
                 ivSplash.setOnClickListener(v -> {
                     Message message = Message.obtain(handler, MSG_OPEN_URL, data.getValue().getSplash().getUrl());
@@ -191,7 +181,7 @@ public class PINActivity extends GeneralActivity {
         Intent i = new Intent(this, setMode ? SettingsActivity.class : MainActivity.class);
         if (setMode || !hasPin() || pin.equals(getTruePin())) startActivity(i);
         if (openUrl != null) {
-            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
+            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(openUrl));
             startActivity(browserIntent);
         }
         super.finish();

+ 12 - 1
app/src/main/java/com/dar/nbook/RegisterActivity.kt

@@ -4,6 +4,7 @@ import android.os.Bundle
 import android.view.MenuItem
 import android.view.View
 import androidx.core.content.ContextCompat
+import com.adjust.sdk.Adjust
 import com.dar.nbook.api.HttpCallback
 import com.dar.nbook.api.HttpClient
 import com.dar.nbook.api.HttpError
@@ -34,6 +35,15 @@ class RegisterActivity : GeneralActivity() {
         supportActionBar!!.setDisplayHomeAsUpEnabled(true)
         supportActionBar!!.setDisplayShowTitleEnabled(true)
 
+        getSharedPreferences("nlogin", MODE_PRIVATE)
+            .getInt("invitor", 0)
+            .let {
+                if (it != 0) {
+                    binding.etInvitor.setText(it.toString())
+                    binding.etInvitor.isEnabled = false
+                }
+            }
+
         binding.register.setOnClickListener {
             binding.username.error = null
             binding.password.error = null
@@ -69,10 +79,11 @@ class RegisterActivity : GeneralActivity() {
     }
 
     private fun register(username: String, password: String, invitor: Int? = null) {
+        val deviceId = Adjust.getAdid()
         binding.register.visibility = View.GONE
         binding.progress.visibility = View.VISIBLE
         HttpClient.request(
-            HttpClient.getApiService().register(UserRegister(username, password, invitor)),
+            HttpClient.getApiService().register(UserRegister(username, password, invitor, deviceId)),
             object : HttpCallback<NUser> {
                 override fun onSuccess(data: NUser) {
                     binding.progress.visibility = View.GONE

+ 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 = "http://147.139.168.134:3000/api/";
+    private static final String BASE_URL = "https://nbook.izouma.com/api/";
 
     private static Retrofit getRetrofit() {
         if (retrofit == null) {

+ 12 - 1
app/src/main/java/com/dar/nbook/api/request/UserRegister.java

@@ -8,10 +8,13 @@ public class UserRegister {
 
     private Integer invitor;
 
-    public UserRegister(String username, String password, Integer invitor) {
+    private String deviceId;
+
+    public UserRegister(String username, String password, Integer invitor, String deviceId) {
         this.username = username;
         this.password = password;
         this.invitor = invitor;
+        this.deviceId = deviceId;
     }
 
     public String getUsername() {
@@ -37,4 +40,12 @@ public class UserRegister {
     public void setInvitor(Integer invitor) {
         this.invitor = invitor;
     }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
 }

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

@@ -32,6 +32,7 @@ import okhttp3.Call;
 import okhttp3.Callback;
 import okhttp3.Request;
 import okhttp3.Response;
+import okhttp3.ResponseBody;
 
 public class VersionChecker {
     private static final String RELEASE_API_URL = "https://api.github.com/repos/Dar9586/NClientV2/releases";

+ 10 - 0
app/src/main/java/com/dar/nbook/components/activities/CrashApplication.java

@@ -38,6 +38,7 @@ import com.google.gson.GsonBuilder;
 import org.acra.ACRA;
 import org.acra.ReportField;
 import org.acra.annotation.AcraCore;
+import org.jsoup.internal.StringUtil;
 
 import java.io.File;
 import java.io.IOException;
@@ -118,6 +119,15 @@ public class CrashApplication extends MultiDexApplication {
         config.setLogLevel(LogLevel.VERBOSE);
         config.setOnAttributionChangedListener(attribution -> {
             LogUtility.d(new GsonBuilder().serializeSpecialFloatingPointValues().create().toJson(attribution));
+            if (!StringUtil.isBlank(attribution.campaign)) {
+                try {
+                    getSharedPreferences("nlogin", MODE_PRIVATE).edit()
+                        .putInt("invitor", Integer.parseInt(attribution.campaign))
+                        .apply();
+                } catch (Exception e) {
+
+                }
+            }
         });
         Adjust.onCreate(config);
 

+ 0 - 80
app/src/main/java/com/dar/nbook/ui/theme/Theme.kt

@@ -1,80 +0,0 @@
-package com.dar.nbook.ui.theme
-
-import android.app.Activity
-import android.os.Build
-import androidx.compose.foundation.isSystemInDarkTheme
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.darkColorScheme
-import androidx.compose.material3.dynamicDarkColorScheme
-import androidx.compose.material3.dynamicLightColorScheme
-import androidx.compose.material3.lightColorScheme
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.SideEffect
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.toArgb
-import androidx.compose.ui.platform.LocalContext
-import androidx.compose.ui.platform.LocalView
-import androidx.core.view.WindowCompat
-
-val Purple80 = Color(0xFFD0BCFF)
-val PurpleGrey80 = Color(0xFFCCC2DC)
-val Pink80 = Color(0xFFEFB8C8)
-
-val Purple40 = Color(0xFF6650a4)
-val PurpleGrey40 = Color(0xFF625b71)
-val Pink40 = Color(0xFF7D5260)
-
-private val DarkColorScheme = darkColorScheme(
-    primary = Purple80,
-    secondary = PurpleGrey80,
-    tertiary = Pink80,
-    surfaceTint = Color(0xFF1C1B1F),
-)
-
-private val LightColorScheme = lightColorScheme(
-    primary = Purple40,
-    secondary = PurpleGrey40,
-    tertiary = Pink40
-
-    /* Other default colors to override
-    background = Color(0xFFFFFBFE),
-    surface = Color(0xFFFFFBFE),
-    onPrimary = Color.White,
-    onSecondary = Color.White,
-    onTertiary = Color.White,
-    onBackground = Color(0xFF1C1B1F),
-    onSurface = Color(0xFF1C1B1F),
-    */
-)
-
-@Composable
-fun NClientV2Theme(
-    darkTheme: Boolean = isSystemInDarkTheme(),
-    // Dynamic color is available on Android 12+
-    dynamicColor: Boolean = true,
-    content: @Composable () -> Unit
-) {
-    val colorScheme = when {
-        dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
-            val context = LocalContext.current
-            if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
-        }
-
-        darkTheme -> DarkColorScheme
-        else -> LightColorScheme
-    }
-    val view = LocalView.current
-    if (!view.isInEditMode) {
-        SideEffect {
-            val window = (view.context as Activity).window
-            window.statusBarColor = colorScheme.primary.toArgb()
-            WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
-        }
-    }
-
-    MaterialTheme(
-        colorScheme = colorScheme,
-        typography = Typography,
-        content = content,
-    )
-}

+ 0 - 34
app/src/main/java/com/dar/nbook/ui/theme/Type.kt

@@ -1,34 +0,0 @@
-package com.dar.nbook.ui.theme
-
-import androidx.compose.material3.Typography
-import androidx.compose.ui.text.TextStyle
-import androidx.compose.ui.text.font.FontFamily
-import androidx.compose.ui.text.font.FontWeight
-import androidx.compose.ui.unit.sp
-
-// Set of Material typography styles to start with
-val Typography = Typography(
-    bodyLarge = TextStyle(
-        fontFamily = FontFamily.Default,
-        fontWeight = FontWeight.Normal,
-        fontSize = 16.sp,
-        lineHeight = 24.sp,
-        letterSpacing = 0.5.sp
-    )
-    /* Other default text styles to override
-    titleLarge = TextStyle(
-        fontFamily = FontFamily.Default,
-        fontWeight = FontWeight.Normal,
-        fontSize = 22.sp,
-        lineHeight = 28.sp,
-        letterSpacing = 0.sp
-    ),
-    labelSmall = TextStyle(
-        fontFamily = FontFamily.Default,
-        fontWeight = FontWeight.Medium,
-        fontSize = 11.sp,
-        lineHeight = 16.sp,
-        letterSpacing = 0.5.sp
-    )
-    */
-)

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

@@ -398,7 +398,6 @@
         <item>japanese</item>
         <item>pretty</item>
     </string-array>
-    <string name="title_activity_nlogin">NLoginActivity</string>
     <string name="register">Register</string>
     <string name="username">Username</string>
     <string name="password">Password</string>

+ 23 - 0
app/src/main/res/xml/network_security_config.xml

@@ -0,0 +1,23 @@
+<network-security-config>
+    <domain-config>
+        <!-- Make sure your URL Server here -->
+        <domain includeSubdomains="true">192.168.6.215:9090</domain>
+        <trust-anchors>
+            <certificates src="user"/>
+            <certificates src="system"/>
+        </trust-anchors>
+    </domain-config>
+
+    <debug-overrides>
+        <trust-anchors>
+            <certificates src="user" />
+            <certificates src="system" />
+        </trust-anchors>
+    </debug-overrides>
+
+    <base-config cleartextTrafficPermitted="true">
+        <trust-anchors>
+            <certificates src="system" />
+        </trust-anchors>
+    </base-config>
+</network-security-config>