-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Ie3686eb553701df55a719d73b0e3ed6917cfb96e
- Loading branch information
1 parent
fc746fa
commit 4a664ab
Showing
31 changed files
with
203 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/xayah/databackup/compose/ui/activity/crash/CrashActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.xayah.databackup.compose.ui.activity.crash | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.core.view.WindowCompat | ||
import com.xayah.databackup.R | ||
import com.xayah.databackup.compose.ui.activity.crash.components.CrashScaffold | ||
import com.xayah.databackup.compose.ui.theme.DataBackupTheme | ||
import com.xayah.databackup.util.GsonUtil | ||
import com.xayah.materialyoufileexplorer.MaterialYouFileExplorer | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
@ExperimentalMaterial3Api | ||
class CrashActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
|
||
val materialYouFileExplorer = MaterialYouFileExplorer().apply { | ||
initialize(this@CrashActivity) | ||
} | ||
|
||
val logs = intent.getStringExtra("crashInfo") ?: "\n" | ||
setContent { | ||
DataBackupTheme { | ||
CrashScaffold(logs) { | ||
materialYouFileExplorer.apply { | ||
isFile = false | ||
toExplorer(this@CrashActivity) { path, _ -> | ||
CoroutineScope(Dispatchers.IO).launch { | ||
try { | ||
val date = SimpleDateFormat( | ||
"yyyy-MM-dd HH:mm:ss", | ||
Locale.CHINA | ||
).format(Date()) | ||
val name = | ||
"Crash-${date.replace(" ", "-").replace(":", "-")}.txt" | ||
GsonUtil.saveToFile( | ||
"${path}/${name}", | ||
logs | ||
) | ||
withContext(Dispatchers.Main) { | ||
Toast.makeText( | ||
this@CrashActivity, | ||
getString(R.string.success), | ||
Toast.LENGTH_SHORT | ||
).show() | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
withContext(Dispatchers.Main) { | ||
Toast.makeText( | ||
this@CrashActivity, | ||
getString(R.string.failed), | ||
Toast.LENGTH_SHORT | ||
).show() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/xayah/databackup/compose/ui/activity/crash/components/Scaffold.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.xayah.databackup.compose.ui.activity.crash.components | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.Warning | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.res.vectorResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import com.xayah.databackup.R | ||
|
||
@ExperimentalMaterial3Api | ||
@Composable | ||
fun CrashScaffold(crashInfo: String, onSaveClick: () -> Unit) { | ||
val colorOnSurfaceVariant = MaterialTheme.colorScheme.onSurfaceVariant | ||
val nonePadding = dimensionResource(R.dimen.padding_none) | ||
val smallPadding = dimensionResource(R.dimen.padding_small) | ||
val mediumPadding = dimensionResource(R.dimen.padding_medium) | ||
val hugePadding = dimensionResource(R.dimen.padding_huge) | ||
val iconMediumSize = dimensionResource(R.dimen.icon_medium_size) | ||
Scaffold( | ||
floatingActionButton = { | ||
FloatingActionButton( | ||
onClick = onSaveClick, | ||
) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_round_save), | ||
contentDescription = null | ||
) | ||
} | ||
}, | ||
floatingActionButtonPosition = FabPosition.Center | ||
) { innerPadding -> | ||
LazyColumn( | ||
modifier = Modifier.padding(mediumPadding, nonePadding), | ||
verticalArrangement = Arrangement.spacedBy(mediumPadding), | ||
) { | ||
item { | ||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Spacer( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height( | ||
innerPadding.calculateTopPadding() * 2 | ||
) | ||
) | ||
Icon( | ||
imageVector = Icons.Rounded.Warning, | ||
contentDescription = null, | ||
tint = colorOnSurfaceVariant, | ||
modifier = Modifier | ||
.size(iconMediumSize) | ||
.padding(nonePadding, nonePadding, nonePadding, smallPadding) | ||
) | ||
Text( | ||
text = stringResource(R.string.app_crashed), | ||
maxLines = 1, | ||
overflow = TextOverflow.Ellipsis, | ||
style = MaterialTheme.typography.titleLarge, | ||
fontWeight = FontWeight.Bold | ||
) | ||
} | ||
} | ||
item { | ||
Text( | ||
text = crashInfo, | ||
style = MaterialTheme.typography.labelSmall | ||
) | ||
} | ||
item { | ||
Spacer( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height( | ||
innerPadding.calculateBottomPadding() + hugePadding | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="?attr/colorControlNormal" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M5,21Q4.175,21 3.587,20.413Q3,19.825 3,19V5Q3,4.175 3.587,3.587Q4.175,3 5,3H16.175Q16.575,3 16.938,3.15Q17.3,3.3 17.575,3.575L20.425,6.425Q20.7,6.7 20.85,7.062Q21,7.425 21,7.825V19Q21,19.825 20.413,20.413Q19.825,21 19,21ZM19,7.85 L16.15,5H5Q5,5 5,5Q5,5 5,5V19Q5,19 5,19Q5,19 5,19H19Q19,19 19,19Q19,19 19,19ZM12,18Q13.25,18 14.125,17.125Q15,16.25 15,15Q15,13.75 14.125,12.875Q13.25,12 12,12Q10.75,12 9.875,12.875Q9,13.75 9,15Q9,16.25 9.875,17.125Q10.75,18 12,18ZM7,10H14Q14.425,10 14.713,9.712Q15,9.425 15,9V7Q15,6.575 14.713,6.287Q14.425,6 14,6H7Q6.575,6 6.287,6.287Q6,6.575 6,7V9Q6,9.425 6.287,9.712Q6.575,10 7,10ZM5,7.85V19Q5,19 5,19Q5,19 5,19Q5,19 5,19Q5,19 5,19V5Q5,5 5,5Q5,5 5,5Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.