Update StoreWisePerformanceActivity.java

This commit is contained in:
gagangoel290
2017-01-13 17:06:57 +05:30
committed by GitHub
parent 15f98f76d4
commit adc58aa2d4
@@ -3,6 +3,7 @@ package cpm.com.gskmtorange.gsk_dailyentry;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -21,6 +22,7 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import cpm.com.gskmtorange.Database.GSKOrangeDB;
import cpm.com.gskmtorange.R;
@@ -36,8 +38,35 @@ public class StoreWisePerformanceActivity extends AppCompatActivity {
StoreWisePerformaceAdapter adapter;
GSKOrangeDB db;
private SharedPreferences preferences;
String store_id, visit_date, username, intime, date, keyAccount_id, class_id, storeType_id;
private SharedPreferences preferences;
private static boolean updateResources(Context context, String language) {
String lang ;
if(language.equalsIgnoreCase("English")){
lang = "EN";
}
else if(language.equalsIgnoreCase("UAE")) {
lang = "AR";
}
else {
lang = "TR";
}
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -51,6 +80,8 @@ public class StoreWisePerformanceActivity extends AppCompatActivity {
db = new GSKOrangeDB(this);
db.open();
updateResources(getApplicationContext(),preferences.getString(CommonString.KEY_LANGUAGE, ""));
//preference data
preferences = PreferenceManager.getDefaultSharedPreferences(this);
store_id = preferences.getString(CommonString.KEY_STORE_ID, null);
@@ -78,12 +109,15 @@ public class StoreWisePerformanceActivity extends AppCompatActivity {
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
try {
updateResources(getApplicationContext(),preferences.getString(CommonString.KEY_LANGUAGE, ""));
storeWisePerformanceList = db.getStoreWisePerformance(store_id);
adapter = new StoreWisePerformaceAdapter(StoreWisePerformanceActivity.this, storeWisePerformanceList);
@@ -94,10 +128,29 @@ public class StoreWisePerformanceActivity extends AppCompatActivity {
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
}
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class StoreWisePerformaceAdapter extends RecyclerView.Adapter<StoreWisePerformaceAdapter.MyViewHolder> {
Context context;
private LayoutInflater inflator;
List<StoreWisePerformaceGetterSetter> list = Collections.emptyList();
private LayoutInflater inflator;
public StoreWisePerformaceAdapter(Context context, List<StoreWisePerformaceGetterSetter> list) {
inflator = LayoutInflater.from(context);
@@ -152,22 +205,5 @@ public class StoreWisePerformanceActivity extends AppCompatActivity {
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
}
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}