User badge
This commit is contained in:
		| @@ -85,6 +85,9 @@ dependencies { | ||||
|     // https://mvnrepository.com/artifact/commons-io/commons-io | ||||
|     implementation 'commons-io:commons-io:2.11.0' | ||||
|  | ||||
|     // Picasso (image loader) | ||||
|     implementation 'com.squareup.picasso:picasso:2.8' | ||||
|  | ||||
|     configurations.all { | ||||
|         resolutionStrategy { | ||||
|             force 'commons-io:commons-io:2.11.0' | ||||
|   | ||||
| @@ -195,7 +195,7 @@ public class MainActivity extends NextcloudMapsStyledActivity { | ||||
|         startActivity(new Intent(this, AboutActivity.class)); | ||||
|     } | ||||
|  | ||||
|     private void switch_account() { | ||||
|     public void switch_account() { | ||||
|         ApiProvider.logout(); | ||||
|         SingleAccountHelper.applyCurrentAccount(this, null); | ||||
|         Intent intent = new Intent(MainActivity.this, LoginActivity.class); | ||||
|   | ||||
| @@ -3,6 +3,8 @@ package it.danieleverducci.nextcloudmaps.fragments; | ||||
| import android.content.DialogInterface; | ||||
| import android.content.Intent; | ||||
| import android.os.Bundle; | ||||
| import android.os.Handler; | ||||
| import android.util.Log; | ||||
| import android.view.View; | ||||
| import android.widget.Toast; | ||||
|  | ||||
| @@ -10,10 +12,19 @@ import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import androidx.appcompat.widget.AppCompatImageButton; | ||||
| import androidx.appcompat.widget.AppCompatImageView; | ||||
| import androidx.fragment.app.Fragment; | ||||
| import androidx.lifecycle.Observer; | ||||
| import androidx.lifecycle.ViewModelProvider; | ||||
|  | ||||
| import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; | ||||
| import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; | ||||
| import com.nextcloud.android.sso.helper.SingleAccountHelper; | ||||
| import com.nextcloud.android.sso.model.SingleSignOnAccount; | ||||
| import com.squareup.picasso.Picasso; | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| import it.danieleverducci.nextcloudmaps.R; | ||||
| import it.danieleverducci.nextcloudmaps.activity.detail.GeofavoriteDetailActivity; | ||||
| import it.danieleverducci.nextcloudmaps.activity.main.GeofavoritesFragmentViewModel; | ||||
| @@ -26,6 +37,7 @@ import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; | ||||
|  * to communicate with the activity | ||||
|  */ | ||||
| public abstract class GeofavoritesFragment extends Fragment { | ||||
|     private final String TAG = "GeofavoritesFragment"; | ||||
|  | ||||
|     protected GeofavoritesFragmentViewModel mGeofavoritesFragmentViewModel; | ||||
|  | ||||
| @@ -54,6 +66,24 @@ public abstract class GeofavoritesFragment extends Fragment { | ||||
|         // Set views | ||||
|         AppCompatImageButton menuButton = view.findViewById(R.id.menu_button); | ||||
|         menuButton.setOnClickListener(v -> ((MainActivity)requireActivity()).openDrawer()); | ||||
|  | ||||
|         View userBadgeContainer = view.findViewById(R.id.user_badge_container); | ||||
|         userBadgeContainer.setOnClickListener(v -> showSwitchAccountDialog()); | ||||
|  | ||||
|         // Set user badge (async) | ||||
|         Handler h = new Handler(); | ||||
|         h.post(() -> { | ||||
|             try { | ||||
|                 SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()); | ||||
|                 String userBadgePath = ssoAccount.url + "/index.php/avatar/" + ssoAccount.userId + "/64"; | ||||
|                 if (getActivity() != null) | ||||
|                     getActivity().runOnUiThread( | ||||
|                             () -> Picasso.get().load(userBadgePath).into((AppCompatImageView)userBadgeContainer.findViewById(R.id.user_badge)) | ||||
|                     ); | ||||
|             } catch (Exception e) { | ||||
|                 Log.e(TAG, "Unable to load user image: " + e.toString()); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -110,4 +140,18 @@ public abstract class GeofavoritesFragment extends Fragment { | ||||
|         ad.show(); | ||||
|     } | ||||
|  | ||||
|     private void showSwitchAccountDialog() { | ||||
|         AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); | ||||
|         builder.setMessage(R.string.dialog_logout_message) | ||||
|                 .setTitle(R.string.dialog_logout_title) | ||||
|                 .setPositiveButton(android.R.string.yes, (dialog, id) -> { | ||||
|                     if (getActivity() != null) | ||||
|                         ((MainActivity) getActivity()).switch_account(); | ||||
|                     dialog.dismiss(); | ||||
|                 }) | ||||
|                 .setNegativeButton(android.R.string.no, (dialog, id) -> dialog.dismiss()); | ||||
|         AlertDialog ad = builder.create(); | ||||
|         ad.show(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										15
									
								
								app/src/main/res/drawable/user_badge_mask.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/src/main/res/drawable/user_badge_mask.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|  | ||||
|     <item> | ||||
|         <shape | ||||
|             android:innerRadius="0dp" | ||||
|             android:shape="oval" | ||||
|             android:useLevel="false"> | ||||
|             <solid android:color="@android:color/transparent" /> | ||||
|             <stroke | ||||
|                 android:width="10dp" | ||||
|                 android:color="#fff" /> | ||||
|         </shape> | ||||
|     </item> | ||||
| </layer-list> | ||||
| @@ -67,6 +67,22 @@ | ||||
|                 android:lines="1" | ||||
|                 android:textSize="16sp" | ||||
|                 android:text="@string/search_in_all"/> | ||||
|  | ||||
|             <!-- User badge --> | ||||
|             <FrameLayout | ||||
|                 android:id="@+id/user_badge_container" | ||||
|                 android:layout_width="?android:attr/actionBarSize" | ||||
|                 android:layout_height="?android:attr/actionBarSize"> | ||||
|                 <androidx.appcompat.widget.AppCompatImageView | ||||
|                     android:id="@+id/user_badge" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
|                     android:padding="10dp"/> | ||||
|                 <View | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
|                     android:background="@drawable/user_badge_mask"/> | ||||
|             </FrameLayout> | ||||
|         </LinearLayout> | ||||
|  | ||||
|     </com.google.android.material.card.MaterialCardView> | ||||
|   | ||||
| @@ -39,6 +39,8 @@ | ||||
|     <string name="dialog_delete_message">Stai per eliminare il geosegnalibro {name}. Procedere?</string> | ||||
|     <string name="dialog_delete_delete">Elimina</string> | ||||
|     <string name="dialog_delete_cancel">Mantieni</string> | ||||
|     <string name="dialog_logout_title">Cambia account</string> | ||||
|     <string name="dialog_logout_message">Vuoi cambiare account?</string> | ||||
|     <string name="list_geofavorite_deleted">Geosegnalibro eliminato</string> | ||||
|     <string name="list_geofavorite_connection_error">Impossibile ottenere la lista dei geosegnalibri</string> | ||||
|  | ||||
|   | ||||
| @@ -38,6 +38,8 @@ | ||||
|     <string name="dialog_delete_message">You are about to delete geofavorite {name}. Proceed?</string> | ||||
|     <string name="dialog_delete_delete">Delete</string> | ||||
|     <string name="dialog_delete_cancel">Maintain</string> | ||||
|     <string name="dialog_logout_title">Switch account</string> | ||||
|     <string name="dialog_logout_message">Do you want to switch account?</string> | ||||
|     <string name="list_geofavorite_deleted">Geofavorite deleted</string> | ||||
|     <string name="list_geofavorite_connection_error">Unable to obtain geofavorites list</string> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user