Skip to content

Commit

Permalink
feat: create sync message setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ViscousPot committed Oct 18, 2024
1 parent f30083e commit 00f1dc0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/viscouspot/gitsync/GitSyncService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class GitSyncService : Service() {
val pushResult = gitManager.uploadChanges(
repoUrl,
gitDirUri,
settingsManager.getSyncMessage(),
authCredentials.first,
authCredentials.second
) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/viscouspot/gitsync/util/GitManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class GitManager(private val context: Context, private val activity: AppCompatAc
return null
}

fun uploadChanges(repoUrl: String, userStorageUri: Uri, username: String, token: String, onSync: () -> Unit): Boolean? {
fun uploadChanges(repoUrl: String, userStorageUri: Uri, syncMessage: String, username: String, token: String, onSync: () -> Unit): Boolean? {
if (!Helper.isNetworkAvailable(context)) {
return false
}
Expand Down Expand Up @@ -328,7 +328,7 @@ class GitManager(private val context: Context, private val activity: AppCompatAc
}
git.commit {
setCommitter(committerName, committerEmail ?: "")
message = "Last Sync: ${currentDateTime.format(formatter)} (Mobile)"
message = syncMessage.format(currentDateTime.format(formatter))
}

returnResult = true
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/viscouspot/gitsync/util/SettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import android.content.Context
import android.net.Uri
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import com.viscouspot.gitsync.R

class SettingsManager internal constructor(context: Context) {
class SettingsManager internal constructor(private val context: Context) {
private val masterKey = MasterKey.Builder(context, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
Expand Down Expand Up @@ -42,6 +43,17 @@ class SettingsManager internal constructor(context: Context) {
}
}

fun getSyncMessage(): String {
return settingsSharedPref.getString("syncOnAppClosed", null) ?: context.getString(R.string.sync_message)
}

fun setSyncMessage(syncMessage: String) {
with(settingsSharedPref.edit()) {
putString("syncMessage", syncMessage)
apply()
}
}

fun getSyncMessageEnabled(): Boolean {
return settingsSharedPref.getBoolean("syncMessageEnabled", false)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<string name="additions">%s ++</string>
<string name="deletions" tools:ignore="TypographyDashes">%s --</string>

<string name="sync_message">Last Sync: %s (Mobile)</string>

<string name="network_unavailable">Network unavailable!\nGitSync will retry when reconnected</string>
<string name="out_of_memory">Application ran out of memory!</string>
<string name="invalid_remote">Invalid remote!</string>
Expand Down

0 comments on commit 00f1dc0

Please sign in to comment.