From 7a679e4bdc5046413143d0d96fd9f978be0c0d45 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 1 Dec 2023 20:47:01 +0300 Subject: [PATCH] login: one for all (fixes #2766) (#2767) Co-authored-by: mutugiii Co-authored-by: dogi --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 5 +- .../planet/myplanet/ui/SplashActivity.java | 7 +- .../ui/sync/DashboardElementActivity.java | 18 +- .../myplanet/ui/sync/LoginActivity.java | 152 ----- ...{TeamLoginActivity.kt => LoginActivity.kt} | 52 +- .../planet/myplanet/ui/sync/SyncActivity.java | 23 +- .../myplanet/ui/sync/UserListAdapter.java | 135 ----- .../myplanet/utilities/SharedPrefManager.kt | 12 - .../res/layout-large-land/activity_login.xml | 474 ++++++++-------- .../res/layout-normal-land/activity_login.xml | 480 ++++++++-------- .../res/layout-small-land/activity_login.xml | 297 ---------- .../res/layout-xlarge-land/activity_login.xml | 482 ++++++++-------- app/src/main/res/layout/activity_login.xml | 530 ++++++++++-------- .../main/res/layout/activity_team_login.xml | 323 ----------- 15 files changed, 1078 insertions(+), 1916 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java rename app/src/main/java/org/ole/planet/myplanet/ui/sync/{TeamLoginActivity.kt => LoginActivity.kt} (75%) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/ui/sync/UserListAdapter.java delete mode 100644 app/src/main/res/layout-small-land/activity_login.xml delete mode 100644 app/src/main/res/layout/activity_team_login.xml diff --git a/app/build.gradle b/app/build.gradle index fcb69771a5..516ccca5d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1174 - versionName "0.11.74" + versionCode 1175 + versionName "0.11.75" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cdef84abd4..4cc8754640 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,7 +43,7 @@ android:usesCleartextTraffic="true" tools:replace="android:label"> - { - inputName.setText(""); - new HomeCommunityDialogFragment().show(getSupportFragmentManager(), ""); - }); - new HomeCommunityDialogFragment().show(getSupportFragmentManager(), ""); - } else { - openCommunity.setVisibility(View.GONE); - } - btnFeedback.setOnClickListener(view -> { - inputName.setText(""); - new FeedbackFragment().show(getSupportFragmentManager(), ""); - }); - - previouslyLoggedIn.setOnClickListener(view -> showUserList()); - - guest = getIntent().getBooleanExtra("guest", false); - String username = getIntent().getStringExtra("username"); - if (guest){ - resetGuestAsMember(username); - } - } - - private void showUserList(){ - LayoutUserListBinding layoutUserListBinding = LayoutUserListBinding.inflate(LayoutInflater.from(this)); - View view = layoutUserListBinding.getRoot(); - - AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); - builder.setTitle(R.string.select_user_to_login) - .setView(view) - .setNegativeButton(R.string.dismiss, null); - - List existingUsers = prefData.getSAVEDUSERS1(); - UserListAdapter adapter = new UserListAdapter(LoginActivity.this, existingUsers); - adapter.setOnItemClickListener(new UserListAdapter.OnItemClickListener() { - @Override - public void onItemClickGuest(String name) { - RealmUserModel model = mRealm.copyFromRealm(RealmUserModel.createGuestUser(name, mRealm, settings)); - if (model == null) { - Utilities.toast(LoginActivity.this, getString(R.string.unable_to_login)); - } else { - saveUserInfoPref(settings, "", model); - onLogin(); - } - } - - @Override - public void onItemClickMember(String name, String password) { - submitForm(name, password); - } - }); - - layoutUserListBinding.listUser.setAdapter(adapter); - layoutUserListBinding.etSearch.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - adapter.getFilter().filter(charSequence); - } - - @Override - public void afterTextChanged(Editable editable) {} - }); - - AlertDialog dialog = builder.create(); - dialog.show(); - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/TeamLoginActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt similarity index 75% rename from app/src/main/java/org/ole/planet/myplanet/ui/sync/TeamLoginActivity.kt rename to app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt index 3a225e1139..8777283537 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/TeamLoginActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import org.ole.planet.myplanet.R -import org.ole.planet.myplanet.databinding.ActivityTeamLoginBinding +import org.ole.planet.myplanet.databinding.ActivityLoginBinding import org.ole.planet.myplanet.datamanager.Service import org.ole.planet.myplanet.model.MyPlanet import org.ole.planet.myplanet.model.RealmMyTeam @@ -19,8 +19,8 @@ import org.ole.planet.myplanet.ui.userprofile.TeamListAdapter import org.ole.planet.myplanet.utilities.FileUtils import org.ole.planet.myplanet.utilities.Utilities -class TeamLoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { - private lateinit var activityTeamLoginBinding: ActivityTeamLoginBinding +class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { + private lateinit var activityLoginBinding: ActivityLoginBinding private var guest = false var users: List? = null var mAdapter: TeamListAdapter? = null @@ -29,23 +29,23 @@ class TeamLoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - activityTeamLoginBinding = ActivityTeamLoginBinding.inflate(layoutInflater) - setContentView(activityTeamLoginBinding.root) - lblLastSyncDate = activityTeamLoginBinding.lblLastSyncDate - inputName = activityTeamLoginBinding.inputName - inputPassword = activityTeamLoginBinding.inputPassword - btnSignIn = activityTeamLoginBinding.btnSignin - syncIcon = activityTeamLoginBinding.syncIcon - becomeMember = activityTeamLoginBinding.becomeMember - btnGuestLogin = activityTeamLoginBinding.btnGuestLogin - imgBtnSetting = activityTeamLoginBinding.imgBtnSetting - syncIcon = activityTeamLoginBinding.syncIcon - lblVersion = activityTeamLoginBinding.lblVersion - btnLang = activityTeamLoginBinding.btnLang - tvAvailableSpace = activityTeamLoginBinding.tvAvailableSpace - openCommunity = activityTeamLoginBinding.openCommunity - btnFeedback = activityTeamLoginBinding.btnFeedback - customDeviceName = activityTeamLoginBinding.customDeviceName + activityLoginBinding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(activityLoginBinding.root) + lblLastSyncDate = activityLoginBinding.lblLastSyncDate + inputName = activityLoginBinding.inputName + inputPassword = activityLoginBinding.inputPassword + btnSignIn = activityLoginBinding.btnSignin + syncIcon = activityLoginBinding.syncIcon + becomeMember = activityLoginBinding.becomeMember + btnGuestLogin = activityLoginBinding.btnGuestLogin + imgBtnSetting = activityLoginBinding.imgBtnSetting + syncIcon = activityLoginBinding.syncIcon + lblVersion = activityLoginBinding.lblVersion + btnLang = activityLoginBinding.btnLang + tvAvailableSpace = activityLoginBinding.tvAvailableSpace + openCommunity = activityLoginBinding.openCommunity + btnFeedback = activityLoginBinding.btnFeedback + customDeviceName = activityLoginBinding.customDeviceName service = Service(this) @@ -116,17 +116,17 @@ class TeamLoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this) } - activityTeamLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this) - activityTeamLoginBinding.recyclerView.adapter = mAdapter + activityLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this) + activityLoginBinding.recyclerView.adapter = mAdapter val layoutManager: RecyclerView.LayoutManager = object : LinearLayoutManager(this) { override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } } - activityTeamLoginBinding.recyclerView.layoutManager = layoutManager - activityTeamLoginBinding.recyclerView.isNestedScrollingEnabled = true - activityTeamLoginBinding.recyclerView.setHasFixedSize(true) + activityLoginBinding.recyclerView.layoutManager = layoutManager + activityLoginBinding.recyclerView.isNestedScrollingEnabled = true + activityLoginBinding.recyclerView.setHasFixedSize(true) } override fun onItemClick(user: User) { @@ -135,7 +135,7 @@ class TeamLoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { .load(user.image) .placeholder(R.drawable.profile) .error(R.drawable.profile) - .into(activityTeamLoginBinding.userProfile) + .into(activityLoginBinding.userProfile) inputName.setText(user.name) } else { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.java index 5346db22da..cf0a149e5e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.java @@ -814,13 +814,7 @@ public void settingDialog(SyncActivity activity) { String url = serverUrlProtocol.getText().toString() + serverUrl.getText().toString(); if (isUrlValid(url)) { prefData.setSELECTEDTEAMID1(selectedTeamId); - if (!prefData.getTEAMMODE1()){ - prefData.setTEAMMODE1(true); - Intent intent = new Intent(this, TeamLoginActivity.class); - startActivity(intent); - } else if (prefData.getTEAMMODE1() && activity instanceof TeamLoginActivity) { - ((TeamLoginActivity) activity).getTeamMembers(); - } + ((LoginActivity) activity).getTeamMembers(); saveConfigAndContinue(dialog); } else { saveConfigAndContinue(dialog); @@ -1202,20 +1196,7 @@ public void onTextChanged(CharSequence s, int i, int i1, int i2) { positiveAction.setEnabled(s.toString().trim().length() > 0 && URLUtil.isValidUrl(protocol + s.toString())); } - public void afterTextChanged(Editable editable) { - switch (view.getId()) { - case R.id.input_name: - validateEditText(inputName, inputLayoutName, getString(R.string.err_msg_name)); - break; - case R.id.input_password: - if(!prefData.getTEAMMODE1()) { - validateEditText(inputPassword, inputLayoutPassword, getString(R.string.err_msg_password)); - } - break; - default: - break; - } - } + public void afterTextChanged(Editable editable) {} } @Override diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/UserListAdapter.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/UserListAdapter.java deleted file mode 100644 index 61c3e2b53d..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/UserListAdapter.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.ole.planet.myplanet.ui.sync; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.Filter; -import android.widget.Filterable; -import android.widget.TextView; - -import androidx.core.content.ContextCompat; - -import com.bumptech.glide.Glide; - -import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.model.User; - -import java.util.ArrayList; -import java.util.List; - -import de.hdodenhof.circleimageview.CircleImageView; - -public class UserListAdapter extends BaseAdapter implements Filterable { - private Context context; - private List userList; - private List filteredUserList; - - private OnItemClickListener onItemClickListener; - - public interface OnItemClickListener { - void onItemClickGuest(String name); - void onItemClickMember(String name, String password); - } - - public UserListAdapter(Context context, List userList) { - this.context = context; - this.userList = userList; - this.filteredUserList = new ArrayList<>(userList); - } - - public void setOnItemClickListener(OnItemClickListener listener) { - this.onItemClickListener = listener; - } - - @Override - public int getCount() { - return filteredUserList.size(); - } - - @Override - public Object getItem(int position) { - return filteredUserList.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View view = convertView; - if (view == null) { - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.user_list_item, null); - } - - TextView userNameTextView = view.findViewById(R.id.userNameTextView); - CircleImageView userProfile = view.findViewById(R.id.userProfile); - userNameTextView.setTextColor(ContextCompat.getColor(context, R.color.md_black_1000)); - - User user = filteredUserList.get(position); - if (user.getFullName().isEmpty() || user.getFullName().equals(" ")) { - userNameTextView.setText(user.getName()); - } else { - userNameTextView.setText(user.getFullName()); - } - - if (!user.getImage().isEmpty()) { - Glide.with(context) - .load(user.getImage()) - .placeholder(R.drawable.profile) - .error(R.drawable.profile) - .into(userProfile); - } - - view.setOnClickListener(v -> { - if (onItemClickListener != null) { - if (user.getSource().equals("guest")) { - onItemClickListener.onItemClickGuest(user.getName()); - } else if (user.getSource().equals("member")) { - onItemClickListener.onItemClickMember(user.getName(), user.getPassword()); - } - } - }); - - return view; - } - - @Override - public Filter getFilter() { - return new Filter() { - @Override - protected FilterResults performFiltering(CharSequence constraint) { - FilterResults results = new FilterResults(); - List filteredList = new ArrayList<>(); - - if (constraint == null || constraint.length() == 0) { - filteredList.addAll(userList); - } else { - String filterPattern = constraint.toString().toLowerCase().trim(); - - for (User item : userList) { - if (item.getName().toLowerCase().contains(filterPattern) || - item.getPassword().toLowerCase().contains(filterPattern)) { - filteredList.add(item); - } - } - } - - results.values = filteredList; - results.count = filteredList.size(); - return results; - } - - @Override - protected void publishResults(CharSequence constraint, FilterResults results) { - filteredUserList.clear(); - filteredUserList.addAll((List) results.values); - notifyDataSetChanged(); - } - }; - } -} diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/SharedPrefManager.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/SharedPrefManager.kt index 2606471718..2af1197faa 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/SharedPrefManager.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/SharedPrefManager.kt @@ -17,7 +17,6 @@ class SharedPrefManager(context: Context) { var REPLIEDNEWSID = "repliedNewsId" var MANUALCONFIG = "manualConfig" var SELECTEDTEAMID = "selectedTeamId" - var TEAMMODE = "teamMode" var FIRSTLAUNCH = "firstLaunch" init { @@ -102,17 +101,6 @@ class SharedPrefManager(context: Context) { editor.apply() } - @JvmName("getTEAMMODE1") - fun getTEAMMODE(): Boolean { - return pref.getBoolean(TEAMMODE, false) - } - - @JvmName("setTEAMMODE1") - fun setTEAMMODE(teamMode: Boolean) { - editor.putBoolean(TEAMMODE, teamMode) - editor.apply() - } - @JvmName("getFIRSTLAUNCH1") fun getFIRSTLAUNCH(): Boolean { return pref.getBoolean(FIRSTLAUNCH, false) diff --git a/app/src/main/res/layout-large-land/activity_login.xml b/app/src/main/res/layout-large-land/activity_login.xml index 80f20ff081..731ba80d6e 100644 --- a/app/src/main/res/layout-large-land/activity_login.xml +++ b/app/src/main/res/layout-large-land/activity_login.xml @@ -5,64 +5,253 @@ android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@drawable/darkblue_gradient"> - + tools:context=".ui.sync.LoginActivity"> + android:orientation="horizontal"> - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + + + + + + + + + + + + + +