Finished language functionality
This commit is contained in:
@@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -52,16 +53,22 @@ public class SettingsFragment extends Fragment {
|
|||||||
// set the language dropdown on the currently selected language stored in the sharedPreferences
|
// set the language dropdown on the currently selected language stored in the sharedPreferences
|
||||||
languageDropdown.setSelection(languageToDropdownPosition(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "")));
|
languageDropdown.setSelection(languageToDropdownPosition(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "")));
|
||||||
|
|
||||||
|
long previousID = languageDropdown.getSelectedItemId();
|
||||||
languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
setLocale(dropdownPositionToLanguage(id));
|
setLocale(dropdownPositionToLanguage(id));
|
||||||
|
if (id != previousID){
|
||||||
|
Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout);
|
||||||
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||||
|
fragmentTransaction.detach(currentFragment);
|
||||||
|
fragmentTransaction.attach(currentFragment);
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -98,6 +105,17 @@ public class SettingsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reloads the fragment
|
||||||
|
*/
|
||||||
|
private void refresh(){
|
||||||
|
Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout);
|
||||||
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||||
|
fragmentTransaction.detach(currentFragment);
|
||||||
|
fragmentTransaction.attach(currentFragment);
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* changes the current language to the desired language and saves this setting in SharedPreferences
|
* changes the current language to the desired language and saves this setting in SharedPreferences
|
||||||
* @param language the desired language to translate to
|
* @param language the desired language to translate to
|
||||||
|
|||||||
Reference in New Issue
Block a user