Skip to content

Commit 760f521

Browse files
committed
Making Production Ready + Code CleanUp + Improved Code Quality - 4
1 parent 210a2fd commit 760f521

139 files changed

Lines changed: 302 additions & 1669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source-code/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
android:allowBackup="true"
1717
android:icon="@mipmap/ic_launcher"
1818
android:label="@string/app_name"
19+
android:supportsRtl="true"
1920
android:theme="@style/AppTheme" >
2021
<activity
2122
android:name=".activity.HomeActivity"

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/AboutBuildmLearn.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import org.buildmlearn.toolkit.R;
1111

12+
import java.util.Locale;
13+
1214
/**
1315
* @brief Gives brief info about BuildmLearn community and toolkit
1416
*/
@@ -30,9 +32,10 @@ protected void onCreate(Bundle savedInstanceState) {
3032
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
3133
String version = pInfo.versionName;
3234
assert findViewById(R.id.app_version) != null;
33-
((TextView)findViewById(R.id.app_version)).setText("Version: " + version);
35+
((TextView) findViewById(R.id.app_version)).setText(String.format(Locale.ENGLISH, "Version: %s", version));
3436
} catch (PackageManager.NameNotFoundException e) {
3537
assert findViewById(R.id.app_version) != null;
38+
assert ((TextView) findViewById(R.id.app_version)) != null;
3639
((TextView)findViewById(R.id.app_version)).setText("Version: 1.0");
3740
e.printStackTrace();
3841
}

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/TemplateActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.support.v7.widget.LinearLayoutManager;
88
import android.support.v7.widget.RecyclerView;
99
import android.support.v7.widget.Toolbar;
10-
import android.view.View;
1110

1211
import org.buildmlearn.toolkit.R;
1312
import org.buildmlearn.toolkit.adapter.TemplateAdapter;
@@ -27,16 +26,18 @@ protected void onCreate(Bundle savedInstanceState) {
2726
setContentView(R.layout.activity_template);
2827
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
2928
ActionBar actionBar = getSupportActionBar();
29+
assert actionBar != null;
3030
actionBar.setDisplayHomeAsUpEnabled(true);
3131
actionBar.setHomeButtonEnabled(true);
3232
TemplateAdapter mAdapter = new TemplateAdapter(this);
3333
RecyclerView mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
34+
assert mRecyclerView != null;
3435
mRecyclerView.setAdapter(mAdapter);
3536
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
3637

3738
mAdapter.setOnClickListener(new TemplateAdapter.SetOnClickListener() {
3839
@Override
39-
public void onItemClick(int position, View view) {
40+
public void onItemClick(int position) {
4041
Intent intent = new Intent(getApplicationContext(), TemplateEditor.class);
4142
intent.putExtra(Constants.TEMPLATE_ID, position);
4243
startActivity(intent);

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/TemplateEditor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ private void setUpTemplateEditor() {
305305
populateMetaView(selectedTemplate.newMetaEditorAdapter(this));
306306
}
307307
setUpActionBar();
308-
} catch (InstantiationException e) {
309-
e.printStackTrace();
310-
} catch (IllegalAccessException e) {
308+
} catch (InstantiationException | IllegalAccessException e) {
311309
e.printStackTrace();
312310
}
313311
}
@@ -409,7 +407,7 @@ public void onClick(DialogInterface dialog, int id) {
409407
return;
410408
}
411409
Uri fileUri = Uri.fromFile(new File(savedFilePath));
412-
ArrayList<Uri> uris = new ArrayList<Uri>();
410+
ArrayList<Uri> uris = new ArrayList<>();
413411
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
414412
sendIntent.setType("application/zip");
415413
uris.add(fileUri);
@@ -426,7 +424,7 @@ public void onClick(DialogInterface dialog, int id) {
426424
String keyPassword = getString(R.string.key_password);
427425
String aliasName = getString(R.string.alias_name);
428426
String aliaspassword = getString(R.string.alias_password);
429-
KeyStoreDetails keyStoreDetails = new KeyStoreDetails("TestKeyStore.jks", keyPassword, aliasName, aliaspassword);
427+
KeyStoreDetails keyStoreDetails = new KeyStoreDetails(keyPassword, aliasName, aliaspassword);
430428
SignerThread signer = new SignerThread(getApplicationContext(), selectedTemplate.getApkFilePath(), saveProject(), keyStoreDetails, selectedTemplate.getAssetsFilePath(), selectedTemplate.getAssetsFileName(TemplateEditor.this));
431429

432430
mApkGenerationDialog = new MaterialDialog.Builder(TemplateEditor.this)
@@ -487,7 +485,7 @@ public void onFail(Exception e) {
487485
keyPassword = getString(R.string.key_password);
488486
aliasName = getString(R.string.alias_name);
489487
aliaspassword = getString(R.string.alias_password);
490-
keyStoreDetails = new KeyStoreDetails("TestKeyStore.jks", keyPassword, aliasName, aliaspassword);
488+
keyStoreDetails = new KeyStoreDetails(keyPassword, aliasName, aliaspassword);
491489
signer = new SignerThread(getApplicationContext(), selectedTemplate.getApkFilePath(), saveProject(), keyStoreDetails, selectedTemplate.getAssetsFilePath(), selectedTemplate.getAssetsFileName(TemplateEditor.this));
492490

493491
mApkGenerationDialog = new MaterialDialog.Builder(TemplateEditor.this)
@@ -616,8 +614,10 @@ private String saveProject() {
616614
EditText authorEditText = (EditText) findViewById(R.id.author_name);
617615
EditText titleEditText = (EditText) findViewById(R.id.template_title);
618616
assert findViewById(R.id.author_name) != null;
617+
assert ((EditText) findViewById(R.id.author_name)) != null;
619618
String author = ((EditText) findViewById(R.id.author_name)).getText().toString();
620619
assert findViewById(R.id.template_title) != null;
620+
assert ((EditText) findViewById(R.id.template_title)) != null;
621621
String title = ((EditText) findViewById(R.id.template_title)).getText().toString();
622622
if ("".equals(author)) {
623623
assert authorEditText != null;
@@ -695,9 +695,11 @@ public void onBackPressed() {
695695
* @return Absolute path of the saved file. Null if there is some error.
696696
* @brief Saves the current project into a .buildmlearn file.
697697
*/
698-
protected String saveDraft() {
698+
private String saveDraft() {
699699

700+
assert ((EditText) findViewById(R.id.author_name)) != null;
700701
String author = ((EditText) findViewById(R.id.author_name)).getText().toString();
702+
assert ((EditText) findViewById(R.id.template_title)) != null;
701703
String title = ((EditText) findViewById(R.id.template_title)).getText().toString();
702704

703705

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/TutorialActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ protected void onCreate(Bundle savedInstanceState) {
2828
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
2929
// mPager.setAdapter(mAdapter);
3030

31+
assert mPager != null;
3132
mPager.setAdapter(mAdapter);
3233

3334

3435
CirclePageIndicator mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
36+
assert mIndicator != null;
3537
mIndicator.setViewPager(mPager);
3638
}
3739

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/DraftProjectAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import org.buildmlearn.toolkit.views.TextViewPlus;
1212

1313
import java.util.ArrayList;
14+
import java.util.Locale;
1415

1516
/**
1617
* Created by scopeinfinity on 10/3/16.
1718
*/
1819
public class DraftProjectAdapter extends BaseAdapter {
1920

20-
private Context mContext;
21-
private ArrayList<SavedProject> data;
21+
private final Context mContext;
22+
private final ArrayList<SavedProject> data;
2223

2324
public DraftProjectAdapter(Context mContext, ArrayList<SavedProject> data) {
2425
this.mContext = mContext;
@@ -68,8 +69,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
6869
}
6970

7071
SavedProject projectData = getItem(position);
71-
holder.draftSubtitle.setText("Last Modified: " + projectData.getTime() );
72-
holder.draftTitle.setText("Drafted on "+projectData.getDate());
72+
holder.draftSubtitle.setText(String.format(Locale.ENGLISH, "Last Modified: %s", projectData.getTime()));
73+
holder.draftTitle.setText(String.format(Locale.ENGLISH, "Drafted on %s", projectData.getDate()));
7374
holder.draftIcon.setText("D");
7475
convertView.setTag(holder);
7576
return convertView;

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/SavedApiAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
public class SavedApiAdapter extends BaseAdapter {
2323

24-
private Context mContext;
25-
private ArrayList<SavedApi> data;
24+
private final Context mContext;
25+
private final ArrayList<SavedApi> data;
2626

2727
public SavedApiAdapter(Context mContext, ArrayList<SavedApi> data) {
2828
this.mContext = mContext;
@@ -72,7 +72,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
7272
}
7373

7474
SavedApi apiData = getItem(position);
75-
holder.details.setText("Modified: " + apiData.getDate() + ", Author: " + apiData.getAuthor());
75+
holder.details.setText(String.format(Locale.ENGLISH, "Modified: %s, Author: ", apiData.getDate(), apiData.getAuthor()));
7676
holder.apkName.setText(apiData.getName());
7777
holder.projectIcon.setText(apiData.getName().substring(0, 1).toUpperCase(Locale.US));
7878
convertView.setTag(holder);

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/SavedProjectAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.buildmlearn.toolkit.adapter;
22

33
import android.content.Context;
4+
import android.support.v4.content.ContextCompat;
45
import android.view.LayoutInflater;
56
import android.view.View;
67
import android.view.ViewGroup;
@@ -81,13 +82,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
8182
}
8283

8384
if (selectedPosition == position) {
84-
convertView.setBackgroundColor(mContext.getResources().getColor(R.color.color_divider));
85+
convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_divider));
8586
} else {
8687
convertView.setBackgroundColor(0);
8788
}
8889

8990
SavedProject projectData = getItem(position);
90-
holder.details.setText("Modified: " + projectData.getDate() + ", Author: " + projectData.getAuthor());
91+
holder.details.setText(String.format(Locale.ENGLISH, "Modified: %s, Author: ", projectData.getDate(), projectData.getAuthor()));
9192
holder.projectName.setText(projectData.getName());
9293
holder.projectIcon.setText(projectData.getName().substring(0, 1).toUpperCase(Locale.US));
9394
convertView.setTag(holder);

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/TemplateAdapter.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int posit
5151
}
5252

5353
View view = inflater.inflate(layoutResource, viewGroup, false);
54-
RecyclerView.ViewHolder viewHolder = new ViewHolder(view);
5554

56-
return viewHolder;
55+
return new ViewHolder(view);
5756
}
5857

59-
public Template getItem(int i) {
58+
private Template getItem(int i) {
6059
return templates[i];
6160
}
6261

@@ -119,14 +118,14 @@ public int getColor() {
119118
}
120119

121120
public interface SetOnClickListener extends ViewHolder.SetOnClickListener {
122-
void onItemClick(int position, View itemView);
121+
void onItemClick(int position);
123122
}
124123

125124
public static class ViewHolder extends RecyclerView.ViewHolder {
126-
public TextView title;
127-
public TextView description;
128-
public ImageView image;
129-
public CardView cardView;
125+
public final TextView title;
126+
public final TextView description;
127+
public final ImageView image;
128+
public final CardView cardView;
130129
SetOnClickListener listener;
131130

132131
public ViewHolder(final View v) {
@@ -141,7 +140,7 @@ public ViewHolder(final View v) {
141140
@Override
142141
public void onClick(View view) {
143142
if (listener != null) {
144-
listener.onItemClick(getAdapterPosition(), v);
143+
listener.onItemClick(getAdapterPosition());
145144
}
146145
}
147146
});
@@ -151,40 +150,24 @@ public ImageView getImage() {
151150
return image;
152151
}
153152

154-
public void setImage(ImageView image) {
155-
this.image = image;
156-
}
157-
158153
public CardView getCardView() {
159154
return cardView;
160155
}
161156

162-
public void setCardView(CardView cardView) {
163-
this.cardView = cardView;
164-
}
165-
166157
public TextView getDescription() {
167158
return description;
168159
}
169160

170-
public void setDescription(TextView description) {
171-
this.description = description;
172-
}
173-
174161
public TextView getTitle() {
175162
return title;
176163
}
177164

178-
public void setTitle(TextView title) {
179-
this.title = title;
180-
}
181-
182165
public void setItemClickListener(SetOnClickListener itemClickListener) {
183166
this.listener = itemClickListener;
184167
}
185168

186169
public interface SetOnClickListener {
187-
void onItemClick(int position, View itemView);
170+
void onItemClick(int position);
188171
}
189172
}
190173
}

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/TutorialAdapter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ private Tutorial getItem(int position) {
4747
return mTutorials[position];
4848
}
4949

50-
public long getItemId(int position) {
51-
return position;
52-
}
53-
5450
/**
5551
* {@inheritDoc}
5652
*/

0 commit comments

Comments
 (0)