Skip to content

Commit

Permalink
Merge pull request #15 from amarradi/settingsFragment
Browse files Browse the repository at this point in the history
Settings fragment
  • Loading branch information
amarradi committed Jun 23, 2022
2 parents bfd8325 + f883908 commit 4ba3753
Show file tree
Hide file tree
Showing 34 changed files with 533 additions and 346 deletions.
18 changes: 13 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ android {

defaultConfig {
applicationId "com.git.amarradi.palatschinkencounter"
minSdkVersion 16
targetSdkVersion 30
versionCode 9
versionName "1.0.6"
minSdkVersion 26
targetSdkVersion 32
versionCode 10
versionName "1.0.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -32,11 +32,19 @@ dependencies {

// Java language implementation
implementation "androidx.preference:preference:$preference_version"
implementation 'androidx.appcompat:appcompat:1.4.2'
/*
implementation 'androidx.appcompat:appcompat:1.3.1'

implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
*/
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

public class AboutActivity extends AppCompatActivity {

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,13 +19,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
TextView havefun = findViewById(R.id.tvhavefun);
TextView oss = findViewById(R.id.itsos);
TextView appVersion = findViewById(R.id.tvVersion);
Typeface typeface = getResources().getFont(R.font.opensans_regular);
appVersion.setTypeface(typeface);
title.setTypeface(typeface);
whatsdo.setTypeface(typeface);
havefun.setTypeface(typeface);
oss.setTypeface(typeface);
//Resources resources = getResources();
Typeface typeface_regular = getResources().getFont(R.font.opensans_regular);
Typeface typeface_bold = getResources().getFont(R.font.opensans_extrabold);
appVersion.setTypeface(typeface_regular);
title.setTypeface(typeface_regular);
whatsdo.setTypeface(typeface_regular);
havefun.setTypeface(typeface_bold);
oss.setTypeface(typeface_regular);
TextView resethow = findViewById(R.id.resethowto);
resethow.setTypeface(typeface_regular);
@SuppressLint({"StringFormatInvalid", "LocalSuppress"}) String version = String.format(getResources().getString(R.string.version), BuildConfig.VERSION_NAME);
appVersion.setText(version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import java.util.Objects;

public class MainActivity<nightMode> extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
public class MainActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener, WipeDataDialog.WipeDialogListener {

public static final String SHARED_PREFS = "sharedPrefs";
public static final String COUNTER = "text";
Expand All @@ -37,7 +35,7 @@ public class MainActivity<nightMode> extends AppCompatActivity implements Shared
private boolean safedNightMode;

@SuppressLint("DefaultLocale")
@RequiresApi(api = Build.VERSION_CODES.O)

@Override
protected void onCreate(Bundle savedInstanceState) {

Expand All @@ -51,6 +49,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

Button counterTextButton = findViewById(R.id.counter_text_button);
counterTextButton.setTypeface(getResources().getFont(R.font.opensans_bold));

textView = findViewById(R.id.textview);
TextView textView_start = findViewById(R.id.tv_startpage);
textView.setTypeface(typeface);
Expand All @@ -59,13 +59,32 @@ protected void onCreate(Bundle savedInstanceState) {
setupSharedPreferences();



textView.setOnLongClickListener(v -> {
openDialog();
return false;
});

SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS,MODE_PRIVATE);
String themes = sharedPreferences.getString(NIGHT_MODE,"");

changeTheme(themes);




/* SharedPreferences sharedPreferencesNDM = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
safedNightMode = sharedPreferencesNDM.getBoolean(NIGHT_MODE, false);
if (safedNightMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
counterTextButton.setTextColor(Color.WHITE);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}

*/
load_data();
updateViews();

Expand All @@ -78,31 +97,74 @@ protected void onCreate(Bundle savedInstanceState) {
updateViews();
}

private void setupSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);

return true;
}

@SuppressLint("NonConstantResourceId")

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_setting:
Intent intentSetting = new Intent(this, SettingActivity.class);
startActivity(intentSetting);
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.item_setting) {
Intent intentSetting = new Intent(this, SettingActivity.class);
startActivity(intentSetting);
return true;
}
return super.onOptionsItemSelected(item);

}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d("key", key);
if (key.equals("theme")) {
loadThemeFromPreference(sharedPreferences);
}
}


// Method to pass value from SharedPreferences
private void loadThemeFromPreference(SharedPreferences sharedPreferences) {
// Log.d("Parzival",sharedPreferences.getString(getString(R.string.theme_active),
// getString(R.string.lightmode_preference_option_value)));
changeTheme(sharedPreferences.getString(getString(R.string.theme_key),
getString(R.string.lightmode_preference_option_value)));
}

// Method to set Color of Text.
private void changeTheme(String theme_value) {
Log.d("changeTheme", theme_value);
if (theme_value.equals("lightmode")||theme_value.equals("hell")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS,MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(NIGHT_MODE,theme_value);
editor.apply();
} else if (theme_value.equals("darkmode")||theme_value.equals("dunkel")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS,MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(NIGHT_MODE,theme_value);
editor.apply();
}
}
/*



public void openDialog() {
WipeDataDialog dialog = new WipeDataDialog();
dialog.show(getSupportFragmentManager(), "open dialog");
}*/
}

public void save_data() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
Expand All @@ -113,8 +175,7 @@ public void save_data() {

public void load_data() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
int safedCounter = sharedPreferences.getInt(COUNTER, 0);
counter = safedCounter;
counter = sharedPreferences.getInt(COUNTER, 0);
}

@SuppressLint("DefaultLocale")
Expand All @@ -123,8 +184,6 @@ public void updateViews() {
}


/*
public void reset_counter() {
counter = 0;
updateViews();
Expand All @@ -136,43 +195,10 @@ public void reset_counter() {
public void onYesClicked() {
reset_counter();
}
*/
private void setupSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}



@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("darkmode")) {
Log.d("Value mode onShared:", key);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
Log.d("Value mode onShared:", key);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
}

// Method to pass value from SharedPreferences
private void loadColorFromPreference(SharedPreferences sharedPreferences) {
Log.d("Parzival",sharedPreferences.getString(getString(R.string.theme_key),
getString(R.string.lightmode_preference_option_value)));
changeDarkLightMode(sharedPreferences.getString(getString(R.string.theme_key),
getString(R.string.lightmode_preference_option_value)));
}
// Method to set Color of Text.
private void changeDarkLightMode(String mode) {
Log.d("Value mode:", mode);
if (mode.equals("lightmode")) {
Log.d("Value mode:", mode);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

} else if(mode.equals("darkmode")) {
Log.d("Value mode:", mode);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,28 @@
package com.git.amarradi.palatschinkencounter;

import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

public class RecipeActivity extends AppCompatActivity {
ListView listView_Recipe;
String[] listItem_Recipe;


@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe);

TextView recipe = findViewById(R.id.tv_recipe_txt);
TextView ingredients = findViewById(R.id.pancake_ingredients);
TextView flour = findViewById(R.id.tv_flour);
TextView eggs = findViewById(R.id.tv_eggs);
TextView milk = findViewById(R.id.tv_milk);
TextView mineralWater = findViewById(R.id.tv_mineral_water);
TextView salt = findViewById(R.id.tv_salt);
TextView preparation = findViewById(R.id.pancake_preparation);
TextView deliuteEggs = findViewById(R.id.tv_dilute_eggs);
TextView addFlour = findViewById(R.id.tv_add_flour);
TextView addMilk = findViewById(R.id.tv_add_oil);
TextView addOil = findViewById(R.id.tv_add_mineral_water);

Typeface typeface = getResources().getFont(R.font.opensans_regular);

recipe.setTypeface(typeface);
ingredients.setTypeface(typeface);
flour.setTypeface(typeface);
eggs.setTypeface(typeface);
milk.setTypeface(typeface);
mineralWater.setTypeface(typeface);
salt.setTypeface(typeface);
preparation.setTypeface(typeface);
deliuteEggs.setTypeface(typeface);
addFlour.setTypeface(typeface);
addMilk.setTypeface(typeface);
addOil.setTypeface(typeface);
listView_Recipe = findViewById(R.id.listViewIngredients);
listItem_Recipe = getResources().getStringArray(R.array.ingredients_array);
final ArrayAdapter<String> arrayAdapter_Ingredients = new ArrayAdapter<>(this,
R.layout.simple_list_item_1, listItem_Recipe);
listView_Recipe.setAdapter(arrayAdapter_Ingredients);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void onBackPressed() {
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
Expand All @@ -31,5 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
}


}
}
Loading

0 comments on commit 4ba3753

Please sign in to comment.