Skip to content

Commit

Permalink
1.修复登陆闪退
Browse files Browse the repository at this point in the history
2.评论区现可以查看
  • Loading branch information
WaitFme committed Nov 14, 2023
1 parent 267443a commit 0544eb3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 60 deletions.
46 changes: 44 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".util.MyApplication"
Expand All @@ -20,13 +20,55 @@
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.CoolbbsYou">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="market" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="coolmarket" android:host="feed" android:pathPattern="/.*" />

<data android:scheme="coolmarket" android:pathPattern="/.*" />

<data android:scheme="coolmarket" android:host="com.coolapk.com" android:pathPattern="/.*" />

<data android:scheme="coolmarket" android:host="www.coolapk.com" android:pathPattern="/.*" />

<data android:scheme="http" android:host="coolapk.com" android:pathPattern="/" />

<data android:scheme="http" android:host="coolapk.com" android:pathPattern="/feed/.*" />

<data android:scheme="http" android:host="www.coolapk.com" android:pathPattern="/" />

<data android:scheme="http" android:host="www.coolapk.com" android:pathPattern="/feed/.*" />

<data android:scheme="https" android:host="coolapk.com" android:pathPattern="/" />

<data android:scheme="https" android:host="coolapk.com" android:pathPattern="/feed/.*" />

<data android:scheme="https" android:host="www.coolapk.com" android:pathPattern="/" />

<data android:scheme="https" android:host="www.coolapk.com" android:pathPattern="/feed/.*" />

<data android:scheme="intent" android:host="www.coolapk.com" android:path="/feed/.*" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.anpe.coolbbsyou.data.remote.service

import android.content.Context
import android.os.Build
import com.anpe.coolbbsyou.constant.Constants
import com.anpe.coolbbsyou.data.remote.cookie.CookieManager
import com.anpe.coolbbsyou.data.remote.domain.details.DetailsModel
Expand Down Expand Up @@ -30,6 +31,7 @@ interface Api2Service {
.callTimeout(5, TimeUnit.SECONDS)
.addInterceptor {
val request = it.request().newBuilder()
.addHeader(Constants.USER_AGENT_KEY, "${System.getProperty("http.agent")} (#Build; ${Build.BRAND}; ${Build.MODEL}; ${Build.DISPLAY}; ${Build.VERSION.RELEASE}) +CoolMarket/13.3.6-2310232-universal")
.addHeader(Constants.DEVICE_CODE_KEY, deviceCode)
.addHeader(Constants.DEVICE_TOKEN_KEY, deviceCode.getTokenV2())
.addHeader(Constants.REQUEST_WIDTH_KEY, Constants.REQUEST_WIDTH_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fun LoginScreen(navControllerScreen: NavHostController, viewModel: MainViewModel
if (it.loginModel.status == 1) {
configSp.edit().putBoolean("LOGIN_STATUS", true).apply()
viewModel.channel.send(MainEvent.GetProfile(it.loginModel.sESSION.uid))
navControllerScreen.popBackStack()
// navControllerScreen.popBackStack()
context.showToast("登陆成功!")
} else {
context.showToast("账号或密码错误!${it.loginModel.status}")
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/anpe/coolbbsyou/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@ package com.anpe.coolbbsyou.ui.main

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.anpe.coolbbsyou.ui.host.screen.ImageScreen
import com.anpe.coolbbsyou.ui.host.screen.LoginScreen
import com.anpe.coolbbsyou.ui.host.screen.MainScreen
Expand All @@ -40,8 +28,6 @@ import com.anpe.coolbbsyou.ui.host.screen.SplashScreen
import com.anpe.coolbbsyou.ui.host.screen.TopicScreen
import com.anpe.coolbbsyou.ui.host.screen.manager.ScreenManager
import com.anpe.coolbbsyou.ui.theme.CoolbbsYouTheme
import com.anpe.coolbbsyou.util.ToastUtils.Companion.showToast
import com.anpe.coolbbsyou.util.Utils.Companion.clickableNoRipple
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.systemuicontroller.rememberSystemUiController

Expand Down
93 changes: 54 additions & 39 deletions app/src/main/java/com/anpe/coolbbsyou/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
).flow.cachedIn(viewModelScope)
_indexState.emit(IndexState.Success(pagingDataFlow))
} catch (e: Exception) {
_indexState.emit(IndexState.Error(e.toString() ?: "error"))
_indexState.emit(IndexState.Error(e.message()))
}
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
try {
DetailsState.Success(repository.getDetails(id = id))
} catch (e: Exception) {
DetailsState.Error(e.localizedMessage ?: "error")
DetailsState.Error(e.message())
}
)
}
Expand All @@ -272,11 +272,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
_suggestState.emit(SuggestState.Loading)
_suggestState.emit(
try {
Log.d("TAG", "getSuggestSearch: $keyword")
SuggestState.Success(repository.getSuggestSearch(keyword = keyword))
} catch (e: Exception) {
Log.d("TAG", "getSuggestSearch: $e")
SuggestState.Error("${e.localizedMessage ?: "UNKNOWN ERROR"}; keyword: $keyword")
SuggestState.Error("${e.message()}; keyword: $keyword")
}
)
}
Expand All @@ -303,7 +301,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
)
}.await())
} catch (e: Exception) {
SearchState.Error(e.localizedMessage ?: "UNKNOWN")
SearchState.Error(e.message())
}
)
}
Expand All @@ -321,7 +319,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
try {
TodayState.Success(repository.getTodayCool(page, url))
} catch (e: Exception) {
TodayState.Error(e.localizedMessage ?: "UNKNOWN")
TodayState.Error(e.message())
}
)
}
Expand All @@ -342,7 +340,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
Log.d(TAG, "loginAccount: $postAccount")
LoginState.Success(postAccount)
} catch (e: Exception) {
LoginState.Error(e.localizedMessage ?: "UNKNOWN")
LoginState.Error(e.message())
}
)
}
Expand All @@ -353,6 +351,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
*/
private fun logoutAccount() {
configSp.edit().putBoolean("LOGIN_STATUS", false).apply()
_globalState.value.isLogin = false
userInfoSp.edit().clear().apply()
MyCookieStore().removeAll()
}
Expand All @@ -366,9 +365,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
try {
val loginInfoModel = repository.getLoginInfo()

var loginStatus = false

Log.d(TAG, "getLoginInfo: $loginInfoModel")
val loginStatus: Boolean

if (loginInfoModel.error == -1) {
loginStatus = false
Expand All @@ -378,9 +375,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
userInfoSp.edit().putInt("UID", loginInfoModel.data.uid.toInt()).apply()
_loginInfoState.emit(LoginInfoState.Success(loginInfoModel))
}

_globalState.value.isLogin = loginStatus
configSp.edit().putBoolean("LOGIN_STATUS", loginStatus).apply()
} catch (e: Exception) {
_loginInfoState.emit(LoginInfoState.Error(e.localizedMessage ?: "UNKNOWN"))
_loginInfoState.emit(LoginInfoState.Error(e.message()))
}
}
}
Expand All @@ -393,15 +392,15 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
viewModelScope.launch {
_profileState.emit(ProfileState.Loading)
try {
if (configSp.getBoolean("LOGIN_STATUS", false)) {
if (globalState.value.isLogin) {
val profileModel = repository.getProfile(uid)
saveProfile(profileModel)
_profileState.emit(ProfileState.Success(profileModel))
} else {
_profileState.emit(ProfileState.UnLogin("UN LOGIN"))
}
} catch (e: Exception) {
_profileState.emit(ProfileState.Error(e.localizedMessage ?: "UNKNOWN"))
_profileState.emit(ProfileState.Error(e.message()))
}
}
}
Expand Down Expand Up @@ -442,7 +441,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
NotificationState.Error("UN LOGIN")
}
} catch (e: Exception) {
NotificationState.Error(e.localizedMessage ?: "UNKNOWN")
NotificationState.Error(e.message())
}
)
}
Expand All @@ -468,7 +467,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
) }
).flow.cachedIn(viewModelScope))
} catch (e: Exception) {
ReplyState.Error(e.localizedMessage ?: "UNKNOWN")
ReplyState.Error(e.message())
}
)
}
Expand All @@ -490,54 +489,70 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
) }
).flow.cachedIn(viewModelScope))
} catch (e: Exception) {
ReplyState.Error(e.localizedMessage ?: "UNKNOWN")
ReplyState.Error(e.message())
}
)
}
}

private fun getFollow(uid: Int) {
viewModelScope.launch {
try {
val followModel = repository.getFollow(uid)
_followState.emit(followModel)
} catch (e: Exception) {
Log.e(TAG, "getFollow: ${e.localizedMessage}")
if (globalState.value.isLogin) {
try {
val followModel = repository.getFollow(uid)
_followState.emit(followModel)
} catch (e: Exception) {
Log.e(TAG, "getFollow: ${e.message()}")
}
} else {
Log.e(TAG, "getFollow: UN_LOGIN")
}
}
}

private fun getUnFollow(uid: Int) {
viewModelScope.launch {
try {
val followModel = repository.getUnFollow(uid)
_followState.emit(followModel)
} catch (e: Exception) {
Log.e(TAG, "getFollow: ${e.localizedMessage}")
if (globalState.value.isLogin) {
try {
val followModel = repository.getUnFollow(uid)
_followState.emit(followModel)
} catch (e: Exception) {
Log.e(TAG, "getFollow: ${e.message()}")
}
} else {
Log.e(TAG, "getUnFollow: UN_LOGIN")
}
}
}

private fun getLike(id: Int) {
viewModelScope.launch {
try {
val likeModel = repository.getLike(id = id)
val likeState = LikeState(isLike = true, likeModel = likeModel)
_likeState.emit(likeState)
} catch (e: Exception) {
Log.e(TAG, "getLike: ${e.localizedMessage}")
if (globalState.value.isLogin) {
try {
val likeModel = repository.getLike(id = id)
val likeState = LikeState(isLike = true, likeModel = likeModel)
_likeState.emit(likeState)
} catch (e: Exception) {
Log.e(TAG, "getLike: ${e.message()}")
}
} else {
Log.e(TAG, "getLike: UN_LOGIN")
}
}
}

private fun getUnlike(id: Int) {
viewModelScope.launch {
try {
val likeModel = repository.getUnlike(id = id)
val likeState = LikeState(isLike = false, likeModel = likeModel)
_likeState.emit(likeState)
} catch (e: Exception) {
Log.e(TAG, "getUnlike: ${e.localizedMessage}")
if (globalState.value.isLogin) {
try {
val likeModel = repository.getUnlike(id = id)
val likeState = LikeState(isLike = false, likeModel = likeModel)
_likeState.emit(likeState)
} catch (e: Exception) {
Log.e(TAG, "getUnlike: ${e.message()}")
}
} else {
Log.e(TAG, "getUnlike: UN_LOGIN")
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/anpe/coolbbsyou/util/TokenDeviceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import com.anpe.coolbbsyou.util.Utils.Companion.getMD5

class TokenDeviceUtils {
companion object {
private fun createDeviceCode(aid: String, mac: String, manufacturer: String, brand: String, model: String, display: String, isRaw: Boolean = true
) = "$aid; ; ; $mac; $manufacturer; $brand; $model; $display; null".getBase64(isRaw).reversed()
private fun createDeviceCode(aid: String, mac: String, manufacturer: String, brand: String, model: String, display: String, str: String, isRaw: Boolean = true
) = "$aid; ; ; $mac; $manufacturer; $brand; $model; $display; $str".getBase64(isRaw).reversed()

fun getDeviceCode(context: Context): String {
val sp = context.getSharedPreferences(Constants.CONFIG_PREFS, Context.MODE_PRIVATE)

val aid = sp.getString("AID", Settings.System.getString(context.contentResolver, Settings.Secure.ANDROID_ID))!!
var aid = sp.getString("AID", Settings.System.getString(context.contentResolver, Settings.Secure.ANDROID_ID))!!
aid = "DUZJlvIF9j-$aid"
val mac = sp.getString("MAC", Utils.randomMacAddress())!!
val manuFactor = Build.MANUFACTURER
val brand = Build.BRAND
val model = Build.MODEL
val display = Build.DISPLAY
val str = "null"

return createDeviceCode(aid, mac, manuFactor, brand, model, display)
return createDeviceCode(aid, mac, manuFactor, brand, model, display, str)
}

fun String.getTokenV2(): String {
Expand Down

0 comments on commit 0544eb3

Please sign in to comment.