mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Added support for butterknife library for view bindings
This commit is contained in:
parent
a997184178
commit
060750b050
6 changed files with 109 additions and 100 deletions
|
|
@ -16,6 +16,8 @@ dependencies {
|
||||||
compile "com.android.support:appcompat-v7:${project.supportLibVersion}"
|
compile "com.android.support:appcompat-v7:${project.supportLibVersion}"
|
||||||
compile "com.android.support:design:${project.supportLibVersion}"
|
compile "com.android.support:design:${project.supportLibVersion}"
|
||||||
compile 'com.google.code.gson:gson:2.7'
|
compile 'com.google.code.gson:gson:2.7'
|
||||||
|
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
|
||||||
|
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,21 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class AboutActivity extends BaseActivity {
|
public class AboutActivity extends BaseActivity {
|
||||||
private TextView versionText;
|
@BindView(R.id.about_version) TextView versionText;
|
||||||
private TextView licenseText;
|
@BindView(R.id.about_license) TextView licenseText;
|
||||||
private TextView improveText;
|
@BindView(R.id.about_improve) TextView improveText;
|
||||||
private TextView privacyPolicyText;
|
@BindView(R.id.about_privacy_policy) TextView privacyPolicyText;
|
||||||
private TextView uploadsToText;
|
@BindView(R.id.about_uploads_to) TextView uploadsToText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
|
ButterKnife.bind(this);
|
||||||
versionText = (TextView) findViewById(R.id.about_version);
|
|
||||||
licenseText = (TextView) findViewById(R.id.about_license);
|
|
||||||
improveText = (TextView) findViewById(R.id.about_improve);
|
|
||||||
privacyPolicyText = (TextView) findViewById(R.id.about_privacy_policy);
|
|
||||||
uploadsToText = (TextView) findViewById(R.id.about_uploads_to);
|
|
||||||
|
|
||||||
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
|
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
|
||||||
versionText.setText(CommonsApplication.APPLICATION_VERSION);
|
versionText.setText(CommonsApplication.APPLICATION_VERSION);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import fr.free.nrw.commons.AboutActivity;
|
import fr.free.nrw.commons.AboutActivity;
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
|
@ -39,9 +41,9 @@ public class ContributionsListFragment extends Fragment {
|
||||||
void refreshSource();
|
void refreshSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GridView contributionsList;
|
@BindView(R.id.contributionsList) GridView contributionsList;
|
||||||
private TextView waitingMessage;
|
@BindView(R.id.waitingMessage) TextView waitingMessage;
|
||||||
private TextView emptyMessage;
|
@BindView(R.id.emptyMessage) TextView emptyMessage;
|
||||||
|
|
||||||
private ContributionController controller;
|
private ContributionController controller;
|
||||||
private static final String TAG = "ContributionsList";
|
private static final String TAG = "ContributionsList";
|
||||||
|
|
@ -49,11 +51,7 @@ public class ContributionsListFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.fragment_contributions, container, false);
|
View v = inflater.inflate(R.layout.fragment_contributions, container, false);
|
||||||
|
ButterKnife.bind(this, v);
|
||||||
|
|
||||||
contributionsList = (GridView) v.findViewById(R.id.contributionsList);
|
|
||||||
waitingMessage = (TextView) v.findViewById(R.id.waitingMessage);
|
|
||||||
emptyMessage = (TextView) v.findViewById(R.id.emptyMessage);
|
|
||||||
|
|
||||||
contributionsList.setOnItemClickListener((AdapterView.OnItemClickListener)getActivity());
|
contributionsList.setOnItemClickListener((AdapterView.OnItemClickListener)getActivity());
|
||||||
if(savedInstanceState != null) {
|
if(savedInstanceState != null) {
|
||||||
|
|
|
||||||
|
|
@ -29,20 +29,28 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import butterknife.OnItemSelected;
|
||||||
|
import butterknife.OnTouch;
|
||||||
import fr.free.nrw.commons.Prefs;
|
import fr.free.nrw.commons.Prefs;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
|
|
||||||
public class SingleUploadFragment extends Fragment {
|
public class SingleUploadFragment extends Fragment {
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
private String license;
|
||||||
|
|
||||||
public interface OnUploadActionInitiated {
|
public interface OnUploadActionInitiated {
|
||||||
void uploadActionInitiated(String title, String description);
|
void uploadActionInitiated(String title, String description);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditText titleEdit;
|
@BindView(R.id.titleEdit) EditText titleEdit;
|
||||||
private EditText descEdit;
|
@BindView(R.id.descEdit) EditText descEdit;
|
||||||
private TextView licenseSummaryView;
|
@BindView(R.id.titleDescButton) Button titleDescButton;
|
||||||
private Spinner licenseSpinner;
|
@BindView(R.id.share_license_summary) TextView licenseSummaryView;
|
||||||
|
@BindView(R.id.licenseSpinner) Spinner licenseSpinner;
|
||||||
|
|
||||||
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
||||||
|
|
||||||
|
|
@ -82,12 +90,7 @@ public class SingleUploadFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_single_upload, null);
|
View rootView = inflater.inflate(R.layout.fragment_single_upload, null);
|
||||||
|
ButterKnife.bind(this, rootView);
|
||||||
titleEdit = (EditText)rootView.findViewById(R.id.titleEdit);
|
|
||||||
descEdit = (EditText)rootView.findViewById(R.id.descEdit);
|
|
||||||
Button titleDescButton = (Button) rootView.findViewById(R.id.titleDescButton);
|
|
||||||
licenseSpinner = (Spinner) rootView.findViewById(R.id.licenseSpinner);
|
|
||||||
licenseSummaryView = (TextView)rootView.findViewById(R.id.share_license_summary);
|
|
||||||
|
|
||||||
ArrayList<String> licenseItems = new ArrayList<>();
|
ArrayList<String> licenseItems = new ArrayList<>();
|
||||||
licenseItems.add(getString(R.string.license_name_cc0));
|
licenseItems.add(getString(R.string.license_name_cc0));
|
||||||
|
|
@ -96,8 +99,8 @@ public class SingleUploadFragment extends Fragment {
|
||||||
licenseItems.add(getString(R.string.license_name_cc_by_four));
|
licenseItems.add(getString(R.string.license_name_cc_by_four));
|
||||||
licenseItems.add(getString(R.string.license_name_cc_by_sa_four));
|
licenseItems.add(getString(R.string.license_name_cc_by_sa_four));
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
final String license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||||
|
|
||||||
Log.d("Single Upload fragment", license);
|
Log.d("Single Upload fragment", license);
|
||||||
|
|
||||||
|
|
@ -108,59 +111,6 @@ public class SingleUploadFragment extends Fragment {
|
||||||
Log.d("Single Upload fragment", "Position:"+position+" "+getString(Utils.licenseNameFor(license)));
|
Log.d("Single Upload fragment", "Position:"+position+" "+getString(Utils.licenseNameFor(license)));
|
||||||
licenseSpinner.setSelection(position);
|
licenseSpinner.setSelection(position);
|
||||||
|
|
||||||
licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
|
|
||||||
//Set selected color to white because it should be readable on random images.
|
|
||||||
TextView selectedText = (TextView) licenseSpinner.getChildAt(0);
|
|
||||||
if (selectedText != null ) {
|
|
||||||
selectedText.setTextColor(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
String licenseName = parent.getItemAtPosition(position).toString();
|
|
||||||
|
|
||||||
String license = Prefs.Licenses.CC_BY_SA_3; // default value
|
|
||||||
if(getString(R.string.license_name_cc0).equals(licenseName)) {
|
|
||||||
license = Prefs.Licenses.CC0;
|
|
||||||
} else if(getString(R.string.license_name_cc_by).equals(licenseName)) {
|
|
||||||
license = Prefs.Licenses.CC_BY_3;
|
|
||||||
} else if(getString(R.string.license_name_cc_by_sa).equals(licenseName)) {
|
|
||||||
license = Prefs.Licenses.CC_BY_SA_3;
|
|
||||||
} else if(getString(R.string.license_name_cc_by_four).equals(licenseName)) {
|
|
||||||
license = Prefs.Licenses.CC_BY_4;
|
|
||||||
} else if(getString(R.string.license_name_cc_by_sa_four).equals(licenseName)) {
|
|
||||||
license = Prefs.Licenses.CC_BY_SA_4;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLicenseSummary(license);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putString(Prefs.DEFAULT_LICENSE, license);
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
titleDescButton.setOnClickListener(new View.OnClickListener()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onClick(View v)
|
|
||||||
{
|
|
||||||
//Retrieve last title and desc entered
|
|
||||||
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
||||||
String title = titleDesc.getString("Title", "");
|
|
||||||
String desc = titleDesc.getString("Desc", "");
|
|
||||||
Log.d(TAG, "Title: " + title + ", Desc: " + desc);
|
|
||||||
|
|
||||||
titleEdit.setText(title);
|
|
||||||
descEdit.setText(desc);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
TextWatcher uploadEnabler = new TextWatcher() {
|
TextWatcher uploadEnabler = new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||||
|
|
@ -180,25 +130,54 @@ public class SingleUploadFragment extends Fragment {
|
||||||
|
|
||||||
setLicenseSummary(license);
|
setLicenseSummary(license);
|
||||||
|
|
||||||
// Open license page on touch
|
|
||||||
licenseSummaryView.setOnTouchListener(new View.OnTouchListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
||||||
if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
|
||||||
intent.setData(Uri.parse(Utils.licenseUrlFor(license)));
|
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnItemSelected(R.id.licenseSpinner) void onLicenseSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
String licenseName = parent.getItemAtPosition(position).toString();
|
||||||
|
|
||||||
|
String license = Prefs.Licenses.CC_BY_SA_3; // default value
|
||||||
|
if(getString(R.string.license_name_cc0).equals(licenseName)) {
|
||||||
|
license = Prefs.Licenses.CC0;
|
||||||
|
} else if(getString(R.string.license_name_cc_by).equals(licenseName)) {
|
||||||
|
license = Prefs.Licenses.CC_BY_3;
|
||||||
|
} else if(getString(R.string.license_name_cc_by_sa).equals(licenseName)) {
|
||||||
|
license = Prefs.Licenses.CC_BY_SA_3;
|
||||||
|
} else if(getString(R.string.license_name_cc_by_four).equals(licenseName)) {
|
||||||
|
license = Prefs.Licenses.CC_BY_4;
|
||||||
|
} else if(getString(R.string.license_name_cc_by_sa_four).equals(licenseName)) {
|
||||||
|
license = Prefs.Licenses.CC_BY_SA_4;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLicenseSummary(license);
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putString(Prefs.DEFAULT_LICENSE, license);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnTouch(R.id.share_license_summary) boolean showLicence(View view, MotionEvent motionEvent) {
|
||||||
|
if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
intent.setData(Uri.parse(Utils.licenseUrlFor(license)));
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.titleDescButton) void setTitleDescButton() {
|
||||||
|
//Retrieve last title and desc entered
|
||||||
|
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
String title = titleDesc.getString("Title", "");
|
||||||
|
String desc = titleDesc.getString("Desc", "");
|
||||||
|
Log.d(TAG, "Title: " + title + ", Desc: " + desc);
|
||||||
|
|
||||||
|
titleEdit.setText(title);
|
||||||
|
descEdit.setText(desc);
|
||||||
|
}
|
||||||
|
|
||||||
private void setLicenseSummary(String license) {
|
private void setLicenseSummary(String license) {
|
||||||
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
|
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,7 @@ buildToolsVersion = 25.0.1
|
||||||
|
|
||||||
minSdkVersion = 15
|
minSdkVersion = 15
|
||||||
targetSdkVersion = 25
|
targetSdkVersion = 25
|
||||||
|
android.useDeprecatedNdk=true
|
||||||
|
|
||||||
|
# Library dependencies
|
||||||
|
BUTTERKNIFE_VERSION=8.4.0
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,34 @@
|
||||||
<message key="ws.notPreceded"
|
<message key="ws.notPreceded"
|
||||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
<module name="VisibilityModifier">
|
||||||
|
<property name="packageAllowed" value="false"/>
|
||||||
|
|
||||||
|
<!-- Butter Knife -->
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindArray" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindBitmap" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindBool" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindColor" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindDimen" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindDrawable" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindInt" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindString" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindView" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="BindViews" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnCheckedChanged" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnClick" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnEditorAction" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnFocusChange" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnItemClick" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnItemLongClick" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnItemSelected" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnLongClick" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnPageChange" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnTextChanged" />
|
||||||
|
<property name="ignoreAnnotationCanonicalNames" value="OnTouch" />
|
||||||
|
</module>
|
||||||
|
|
||||||
<module name="OneStatementPerLine"/>
|
<module name="OneStatementPerLine"/>
|
||||||
<module name="MultipleVariableDeclarations"/>
|
<module name="MultipleVariableDeclarations"/>
|
||||||
<module name="ArrayTypeStyle"/>
|
<module name="ArrayTypeStyle"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue