Skip to content

Commit

Permalink
Crashlytics #2
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Mar 8, 2016
1 parent b902aea commit 4d58b16
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitchPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.SwitchPreference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
Expand All @@ -28,8 +29,6 @@ public QKSwitchPreference(Context context, OnPreferenceClickListener onPreferenc
setKey(key);
setEnabled(true);
mDefaultValue = prefs.getBoolean(key, defaultValue);
setLayoutResource(R.layout.list_item_preference);
setWidgetLayoutResource(R.layout.view_switch);
if (title != 0) setTitle(title);
if (summary != 0) setSummary(summary);
}
Expand All @@ -40,24 +39,30 @@ public View getView() {

@Override
public View getView(View convertView, ViewGroup parent) {
View view = super.getView(convertView, parent);
view.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_preference, parent, false);
convertView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));

mCheckBox = (QKSwitch) view.findViewById(android.R.id.checkbox);

LinearLayout frameLayout = (LinearLayout) convertView.findViewById(android.R.id.widget_frame);
LayoutInflater.from(getContext()).inflate(R.layout.view_switch, frameLayout);
}
super.onBindView(convertView);

mCheckBox = (QKSwitch) convertView.findViewById(android.R.id.checkbox);
mCheckBox.setChecked(mDefaultValue);

view.setOnClickListener(v -> {
convertView.setOnClickListener(v -> {
mPrefs.edit().putBoolean(getKey(), !mCheckBox.isChecked()).apply();
mCheckBox.setChecked(!mCheckBox.isChecked());
if (mOnPreferenceClickListener != null) {
mOnPreferenceClickListener.onPreferenceClick(QKSwitchPreference.this);
}
});


return view;
return convertView;
}

@Override
Expand Down

0 comments on commit 4d58b16

Please sign in to comment.