Finished language functionality

This commit is contained in:
Bart
2021-01-05 17:19:09 +01:00
parent f7a2a79d00
commit 00d306631b

View File

@@ -8,6 +8,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.view.LayoutInflater;
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
languageDropdown.setSelection(languageToDropdownPosition(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "")));
long previousID = languageDropdown.getSelectedItemId();
languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long 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
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
* @param language the desired language to translate to