mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #409 from maskaravivek/butterknife
Added support for butterknife library for view bindings
This commit is contained in:
commit
75f2201000
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:design:${project.supportLibVersion}"
|
||||
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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,23 +7,21 @@ import android.widget.TextView;
|
|||
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class AboutActivity extends BaseActivity {
|
||||
private TextView versionText;
|
||||
private TextView licenseText;
|
||||
private TextView improveText;
|
||||
private TextView privacyPolicyText;
|
||||
private TextView uploadsToText;
|
||||
@BindView(R.id.about_version) TextView versionText;
|
||||
@BindView(R.id.about_license) TextView licenseText;
|
||||
@BindView(R.id.about_improve) TextView improveText;
|
||||
@BindView(R.id.about_privacy_policy) TextView privacyPolicyText;
|
||||
@BindView(R.id.about_uploads_to) TextView uploadsToText;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
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);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
|
||||
versionText.setText(CommonsApplication.APPLICATION_VERSION);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import android.widget.Toast;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.AboutActivity;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
|
@ -45,9 +47,9 @@ public class ContributionsListFragment extends Fragment {
|
|||
void refreshSource();
|
||||
}
|
||||
|
||||
private GridView contributionsList;
|
||||
private TextView waitingMessage;
|
||||
private TextView emptyMessage;
|
||||
@BindView(R.id.contributionsList) GridView contributionsList;
|
||||
@BindView(R.id.waitingMessage) TextView waitingMessage;
|
||||
@BindView(R.id.emptyMessage) TextView emptyMessage;
|
||||
|
||||
private ContributionController controller;
|
||||
private static final String TAG = "ContributionsList";
|
||||
|
|
@ -55,11 +57,7 @@ public class ContributionsListFragment extends Fragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_contributions, container, false);
|
||||
|
||||
|
||||
contributionsList = (GridView) v.findViewById(R.id.contributionsList);
|
||||
waitingMessage = (TextView) v.findViewById(R.id.waitingMessage);
|
||||
emptyMessage = (TextView) v.findViewById(R.id.emptyMessage);
|
||||
ButterKnife.bind(this, v);
|
||||
|
||||
contributionsList.setOnItemClickListener((AdapterView.OnItemClickListener)getActivity());
|
||||
if(savedInstanceState != null) {
|
||||
|
|
|
|||
|
|
@ -29,20 +29,28 @@ import android.widget.TextView;
|
|||
|
||||
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.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
||||
public class SingleUploadFragment extends Fragment {
|
||||
private SharedPreferences prefs;
|
||||
private String license;
|
||||
|
||||
public interface OnUploadActionInitiated {
|
||||
void uploadActionInitiated(String title, String description);
|
||||
}
|
||||
|
||||
private EditText titleEdit;
|
||||
private EditText descEdit;
|
||||
private TextView licenseSummaryView;
|
||||
private Spinner licenseSpinner;
|
||||
@BindView(R.id.titleEdit) EditText titleEdit;
|
||||
@BindView(R.id.descEdit) EditText descEdit;
|
||||
@BindView(R.id.titleDescButton) Button titleDescButton;
|
||||
@BindView(R.id.share_license_summary) TextView licenseSummaryView;
|
||||
@BindView(R.id.licenseSpinner) Spinner licenseSpinner;
|
||||
|
||||
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
||||
|
||||
|
|
@ -82,12 +90,7 @@ public class SingleUploadFragment extends Fragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_single_upload, null);
|
||||
|
||||
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);
|
||||
ButterKnife.bind(this, rootView);
|
||||
|
||||
ArrayList<String> licenseItems = new ArrayList<>();
|
||||
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_sa_four));
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final String license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
|
||||
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)));
|
||||
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() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
|
|
@ -180,25 +130,54 @@ public class SingleUploadFragment extends Fragment {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
@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) {
|
||||
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,7 @@ buildToolsVersion = 25.0.1
|
|||
|
||||
minSdkVersion = 15
|
||||
targetSdkVersion = 25
|
||||
android.useDeprecatedNdk=true
|
||||
|
||||
# Library dependencies
|
||||
BUTTERKNIFE_VERSION=8.4.0
|
||||
|
|
|
|||
|
|
@ -77,6 +77,34 @@
|
|||
<message key="ws.notPreceded"
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||
</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="MultipleVariableDeclarations"/>
|
||||
<module name="ArrayTypeStyle"/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue