Skip to content

Commit

Permalink
Added SpinnerFragment. Added abil. 2 switch between 2 themes. still b…
Browse files Browse the repository at this point in the history
…uggy.
  • Loading branch information
aiman-al-masoud committed Jul 19, 2021
1 parent 75589b4 commit e653853
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public enum SETTINGS_TAGS {

TEXT_SIZE(TAG_TYPES.INT, 18),

LAUNCH_TO_BLANK_PAGE(TAG_TYPES.BOOLEAN, false);
LAUNCH_TO_BLANK_PAGE(TAG_TYPES.BOOLEAN, false),

THEME(TAG_TYPES.STRING, "LIGHT");



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import androidx.appcompat.app.AppCompatActivity;

import com.luxlunaris.noadpadlight.R;
import com.luxlunaris.noadpadlight.control.classes.SETTINGS_TAGS;
import com.luxlunaris.noadpadlight.control.classes.Settings;

import java.util.List;

Expand All @@ -33,7 +35,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);

if(!GOT_INITIALIZED){
setTheme(THEMES.getThemeByName("DARK"));
String themeName = Settings.getString(SETTINGS_TAGS.THEME);
setTheme(THEMES.getThemeByName(themeName));
}

super.onCreate(savedInstanceState);
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/luxlunaris/noadpadlight/ui/PageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.widget.Button;

import com.luxlunaris.noadpadlight.R;
import com.luxlunaris.noadpadlight.control.classes.SETTINGS_TAGS;
import com.luxlunaris.noadpadlight.control.classes.Settings;
import com.luxlunaris.noadpadlight.control.interfaces.PageListener;
import com.luxlunaris.noadpadlight.model.interfaces.Page;

Expand Down Expand Up @@ -61,6 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

View view =inflater.inflate(R.layout.fragment_page, container, false);




pageButton = (Button)view.findViewById(R.id.pageButton);

pageButton.setText(page.getPreview());
Expand All @@ -86,6 +91,17 @@ public boolean onLongClick(View v) {
});




///
THEMES theme = THEMES.getThemeByName(Settings.getString(SETTINGS_TAGS.THEME) );
pageButton.setBackgroundColor(theme.BG_COLOR);
pageButton.setTextColor(theme.FG_COLOR);

///



return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().beginTransaction().add(linearLayout.getId(), lauchToBlankPageToggle, "" ).commit();


SpinnerFragment spinner = SpinnerFragment.newInstance(SETTINGS_TAGS.THEME, THEMES.values(), "Select the app-theme:");
getSupportFragmentManager().beginTransaction().add(linearLayout.getId(), spinner, "").commit();



}

Expand Down
114 changes: 114 additions & 0 deletions app/src/main/java/com/luxlunaris/noadpadlight/ui/SpinnerFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.luxlunaris.noadpadlight.ui;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.luxlunaris.noadpadlight.R;
import com.luxlunaris.noadpadlight.control.classes.SETTINGS_TAGS;
import com.luxlunaris.noadpadlight.control.classes.Settings;


public class SpinnerFragment extends Fragment {


/**
* Defines the options that will be displayed by the spinner
*/
Enum[] optionsEnum;

/**
* Specifies the setting to be changed
*/
SETTINGS_TAGS settingTag;

/**
* Text to be displayed to the user.
*/
String text;

/**
* The spinner view itself.
*/
Spinner spinner;


public SpinnerFragment() {
// Required empty public constructor
}


public static SpinnerFragment newInstance(SETTINGS_TAGS settingTag, Enum[] optionsEnum, String text) {
SpinnerFragment fragment = new SpinnerFragment();
fragment.optionsEnum = optionsEnum;
fragment.settingTag = settingTag;
fragment.text = text;
return fragment;
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_spinner, container, false);


//set the text that outlines the spinner's purpose
((TextView)(view.findViewById(R.id.spinner_text))).setText(text);


spinner = view.findViewById(R.id.spinner);
spinner.setAdapter(new ArrayAdapter<Enum>(this.getContext(), R.layout.support_simple_spinner_dropdown_item, optionsEnum ) );

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Settings.setTagValue(settingTag, optionsEnum[position].toString());
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});







return view;

}


@Override
public void onResume() {
super.onResume();

String tagValue = Settings.getString(settingTag);

int i;
for(i =0; i<optionsEnum.length; i++){
if(tagValue.equals(optionsEnum[i].toString())){
break;
}
}


spinner.setSelection(i);
}




}
Binary file added app/src/main/res/drawable/magn2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions app/src/main/res/layout/fragment_spinner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.SpinnerFragment">

<!-- TODO: Update blank fragment layout -->

<Spinner
android:id="@+id/spinner"
android:layout_width="274dp"
android:layout_height="44dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.306"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_text" />

<TextView
android:id="@+id/spinner_text"
android:layout_width="257dp"
android:layout_height="72dp"
android:layout_marginTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.272"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/pages_activity_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<item
android:id="@+id/app_bar_search"
android:icon="@android:drawable/ic_search_category_default"
android:icon="@drawable/magn2"
android:title="Search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/reader_activity_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<item
android:id="@+id/search_token"
android:icon="@drawable/ic_search_black_24dp"
android:icon="@drawable/magn2"
android:title="Search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
Expand Down

0 comments on commit e653853

Please sign in to comment.