Skip to content

Commit

Permalink
Synchronize the modified avatar to local
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Dec 6, 2024
1 parent 1f77f97 commit 79ae105
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
Expand Down Expand Up @@ -114,6 +115,17 @@ public static Bitmap getOwnerAvatarBitmap(Context context, String accountName, b
return BitmapFactory.decodeFile(avaterFile.getPath());
}

public static void updateOwnerAvatar(Context context, String accountName, String newAvatar) {
try (DatabaseHelper databaseHelper = new DatabaseHelper(context); SQLiteDatabase db = databaseHelper.getWritableDatabase()) {
ContentValues contentValues = new ContentValues();
contentValues.put("avatar", newAvatar);
int rowsAffected = db.update(DatabaseHelper.OWNERS_TABLE, contentValues, "account_name = ?", new String[]{accountName});
Log.d(TAG, "updateOwnerAvatar affected: " + rowsAffected);
} catch (Exception e) {
Log.e(TAG, "Error updating avatar: " + e.getMessage());
}
}

public static String loadUserInfo(Context context, Account account) {
try {
URLConnection conn = new URL(USERINFO_URL).openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import android.accounts.Account
import android.accounts.AccountManager
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.widget.ProgressBar
import android.widget.RelativeLayout
import android.widget.RelativeLayout.LayoutParams.MATCH_PARENT
import android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import org.json.JSONException
import org.json.JSONObject
import org.microg.gms.auth.AuthConstants
import org.microg.gms.common.Constants
import org.microg.gms.people.PeopleManager

private const val TAG = "AccountSettings"

Expand Down Expand Up @@ -131,6 +133,7 @@ private val ACTION_TO_SCREEN_ID = hashMapOf(
class MainActivity : AppCompatActivity() {
private lateinit var webView: WebView
private var accountName: String? = null
private var resultBundle: Bundle? = null

private fun getSelectedAccountName(): String? = null

Expand Down Expand Up @@ -205,8 +208,16 @@ class MainActivity : AppCompatActivity() {
}
}

private fun updateLocalAccountAvatar(newAvatarUrl: String?) {
if (TextUtils.isEmpty(newAvatarUrl) || accountName == null) {
return
}
lifecycleScope.launchWhenCreated {
PeopleManager.updateOwnerAvatar(this@MainActivity, accountName, newAvatarUrl)
}
}

private inner class UiBridge {
private var resultBundle: Bundle? = null

@JavascriptInterface
fun close() {
Expand Down Expand Up @@ -287,6 +298,9 @@ class MainActivity : AppCompatActivity() {
fun setResult(resultJsonStr: String?) {
Log.d(TAG, "setResult: resultJsonStr -> $resultJsonStr")
val map = jsonToMap(resultJsonStr) ?: return
if (map.containsKey(KEY_UPDATED_PHOTO_URL)) {
updateLocalAccountAvatar(map[KEY_UPDATED_PHOTO_URL])
}
resultBundle = Bundle().apply {
for ((key, value) in map) {
putString("result.$key", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ const val EXTRA_THEME_CHOICE = "extra.themeChoice"
const val EXTRA_SCREEN_MY_ACTIVITY_PRODUCT = "extra.screen.myactivityProduct"
const val EXTRA_SCREEN_KID_ONBOARDING_PARAMS = "extra.screen.kidOnboardingParams"

const val KEY_UPDATED_PHOTO_URL = "updatedPhotoUrl"

const val OPTION_SCREEN_FLAVOR = "screenFlavor"

0 comments on commit 79ae105

Please sign in to comment.