Archived
Fixed wrong text being saved in settings, also implemented orientation changes
This commit is contained in:
@@ -15,6 +15,7 @@ android {
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,14 @@
|
||||
<activity
|
||||
android:name=".Main"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:theme="@style/AppThemeLight.Launcher"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
|
||||
<!-- android:screenOrientation="portrait"-->
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -15,6 +16,7 @@ import com.madapps.prefrences.EasyPrefrences;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@@ -49,7 +51,9 @@ public class FragmentPersonal extends Fragment {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()),
|
||||
linearLayoutManager = new LinearLayoutManager(getContext()),
|
||||
gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
private ArrayList<Subst> planCardList;
|
||||
private TextView bottomSheetText;
|
||||
private SubstViewModel substViewModel;
|
||||
@@ -62,6 +66,19 @@ public class FragmentPersonal extends Fragment {
|
||||
return inflater.inflate(R.layout.plan, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
layoutManager = linearLayoutManager;
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
layoutManager = gridLayoutManager;
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
@@ -75,8 +92,15 @@ public class FragmentPersonal extends Fragment {
|
||||
|
||||
planCardList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linearRecycler);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
layoutManager = linearLayoutManager;
|
||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
layoutManager = gridLayoutManager;
|
||||
}
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new CardAdapter(planCardList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -14,6 +15,7 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@@ -45,7 +47,9 @@ public class FragmentPlan extends Fragment {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()),
|
||||
linearLayoutManager = new LinearLayoutManager(getContext()),
|
||||
gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
private ArrayList<Subst> planCardList;
|
||||
private TextView bottomSheetText;
|
||||
private SubstViewModel substViewModel;
|
||||
@@ -56,6 +60,19 @@ public class FragmentPlan extends Fragment {
|
||||
return inflater.inflate(R.layout.plan, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
layoutManager = linearLayoutManager;
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
layoutManager = gridLayoutManager;
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
@@ -68,8 +85,15 @@ public class FragmentPlan extends Fragment {
|
||||
|
||||
planCardList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linearRecycler);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
layoutManager = linearLayoutManager;
|
||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
layoutManager = gridLayoutManager;
|
||||
}
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new CardAdapter(planCardList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
@@ -289,9 +289,13 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
}, 600)
|
||||
}
|
||||
|
||||
val userPlan: String = when (prefs.getString("username", "")[prefs.getString("username", "").length - 1].toString().toLowerCase()) {
|
||||
"s", "x", "z" -> prefs.getString("username", "") + getString(R.string.nosplan)
|
||||
else -> prefs.getString("username", "") + getString(R.string.splan)
|
||||
val userPlan: String = if (prefs.getString("username", "").toString().isNotEmpty()) {
|
||||
when (prefs.getString("username", "")[prefs.getString("username", "").length - 1].toString().toLowerCase()) {
|
||||
"s", "x", "z" -> prefs.getString("username", "") + getString(R.string.nosplan)
|
||||
else -> prefs.getString("username", "") + getString(R.string.splan)
|
||||
}
|
||||
} else {
|
||||
getString(R.string.personalplan)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("defaultPersonalised", false)) {
|
||||
|
||||
@@ -115,7 +115,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
edit.putString("classes", txtName.text.toString()).apply()
|
||||
edit.putString("classes", txtClasses.text.toString()).apply()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -124,7 +124,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
edit.putString("courses", txtName.text.toString()).apply()
|
||||
edit.putString("courses", txtCourses.text.toString()).apply()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -451,11 +451,16 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
else -> Toast.makeText(mContext, getString(R.string.nothinghappened), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
alertDialog.setView(dialogView)
|
||||
alertDialog.show()
|
||||
return true
|
||||
}
|
||||
|
||||
// override fun onDetach() {
|
||||
// super.onDetach()
|
||||
// edit.apply()
|
||||
// }
|
||||
|
||||
private fun getDiagnosticsText(prefs: SharedPreferences): String {
|
||||
return "First Launch: " + prefs.getString("firstTimeDev", "") +
|
||||
"\n\nApp launched: " + prefs.getInt("launchDev", 0) +
|
||||
|
||||
Reference in New Issue
Block a user