Skip to content

Commit

Permalink
Code cleaned after migration to AndroidX and Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkisum committed Feb 17, 2019
1 parent a69fc06 commit 98a7539
Show file tree
Hide file tree
Showing 28 changed files with 284 additions and 477 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
*.iml
.gradle
/local.properties
.DS_Store
/build
/captures
.idea/
app/libs/
app/proguard-rules.pro
app/src/androidTest/
app/src/test/
doc/
gradle.properties
gradle/
gradlew
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.alkisum.android.cloudrun"
minSdkVersion 18
targetSdkVersion 28
versionCode 15
versionName "4.0"
versionCode 16
versionName "4.1.dev"
buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Activity listing information about the application.
*
* @author Alkisum
* @version 4.0
* @version 4.1
* @since 1.2
*/
public class AboutActivity extends AppCompatActivity {
Expand Down Expand Up @@ -64,16 +64,11 @@ public final void onCreate(final Bundle savedInstanceState) {
// Github
Preference githubPreference = findPreference(Pref.GITHUB);
githubPreference.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(
final Preference preference) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(getString(
R.string.about_github)));
startActivity(intent);
return false;
}
preference -> {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(getString(R.string.about_github)));
startActivity(intent);
return false;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

Expand All @@ -30,7 +29,7 @@
* Activity to add a session manually to the database.
*
* @author Alkisum
* @version 3.0
* @version 4.1
* @since 2.0
*/
public class AddSessionActivity extends AppCompatActivity implements
Expand Down Expand Up @@ -121,28 +120,22 @@ public final boolean onOptionsItemSelected(final MenuItem item) {
* ClickListener for the ListView items.
*/
private final AdapterView.OnItemClickListener onItemClickListener =
new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(final AdapterView<?> adapterView,
final View view, final int position,
final long id) {
switch (position) {
case AddSessionListAdapter.DATE:
showDatePickerDialog();
break;
case AddSessionListAdapter.TIME:
showTimePickerDialog();
break;
case AddSessionListAdapter.DURATION:
showDurationDialog();
break;
case AddSessionListAdapter.DISTANCE:
showDistanceDialog();
break;
default:
break;
}
(adapterView, view, position, id) -> {
switch (position) {
case AddSessionListAdapter.DATE:
showDatePickerDialog();
break;
case AddSessionListAdapter.TIME:
showTimePickerDialog();
break;
case AddSessionListAdapter.DURATION:
showDurationDialog();
break;
case AddSessionListAdapter.DISTANCE:
showDistanceDialog();
break;
default:
break;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
Expand Down Expand Up @@ -55,7 +54,7 @@
* Activity listing the history of sessions.
*
* @author Alkisum
* @version 4.0
* @version 4.1
* @since 1.0
*/
public class HistoryActivity extends AppCompatActivity implements
Expand Down Expand Up @@ -201,12 +200,7 @@ protected final void onActivityResult(final int requestCode,
Snackbar.make(fab, R.string.session_delete_snackbar,
Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo,
new View.OnClickListener() {
@Override
public void onClick(final View v) {
restoreSessions(session);
}
}).show();
v -> restoreSessions(session)).show();
}
}
}
Expand All @@ -217,43 +211,30 @@ public void onClick(final View v) {
private void setGui() {
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (isEditMode()) {
disableEditMode();
} else {
finish();
}
toolbar.setNavigationOnClickListener(v -> {
if (isEditMode()) {
disableEditMode();
} else {
finish();
}
});

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> adapterView,
final View view, final int position,
final long id) {
if (listAdapter.isEditMode()) {
listAdapter.changeSessionSelectedState(position);
listAdapter.notifyDataSetInvalidated();
} else {
Intent intent = new Intent(HistoryActivity.this,
SessionActivity.class);
intent.putExtra(SessionActivity.ARG_SESSION_ID, id);
startActivityForResult(intent, SESSION_REQUEST_CODE);
}
listView.setOnItemClickListener((adapterView, view, position, id) -> {
if (listAdapter.isEditMode()) {
listAdapter.changeSessionSelectedState(position);
listAdapter.notifyDataSetInvalidated();
} else {
Intent intent = new Intent(HistoryActivity.this,
SessionActivity.class);
intent.putExtra(SessionActivity.ARG_SESSION_ID, id);
startActivityForResult(intent, SESSION_REQUEST_CODE);
}
});

listView.setOnItemLongClickListener(
new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(
final AdapterView<?> adapterView, final View view,
final int i, final long l) {
enableEditMode(i);
return true;
}
(adapterView, view, i, l) -> {
enableEditMode(i);
return true;
});

List<Session> sessions = Sessions.loadSessions(ignoreSessionId);
Expand All @@ -266,12 +247,9 @@ public boolean onItemLongClick(
listView.setAdapter(listAdapter);

swipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshList();
swipeRefreshLayout.setRefreshing(false);
}
() -> {
refreshList();
swipeRefreshLayout.setRefreshing(false);
}
);
}
Expand Down Expand Up @@ -436,12 +414,9 @@ public final void onSubmit(final int operation,
}
}

runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
}
runOnUiThread(() -> {
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
});
}

Expand Down Expand Up @@ -612,12 +587,9 @@ public final void onDeletedEvent(final DeletedEvent event) {
final Restorable[] sessions = Deletables.toRestorables(
event.getDeletedEntities());
snackbar.setAction(R.string.action_undo,
new View.OnClickListener() {
@Override
public void onClick(final View v) {
// restore sessions
restoreSessions(sessions);
}
v -> {
// restore sessions
restoreSessions(sessions);
});
}
snackbar.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;

import com.alkisum.android.cloudrun.BuildConfig;
import com.alkisum.android.cloudrun.R;
Expand Down Expand Up @@ -34,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Expand All @@ -45,7 +44,7 @@
* Activity showing current location and tracking session on map.
*
* @author Alkisum
* @version 4.0
* @version 4.1
* @since 3.0
*/
public class MapActivity extends AppCompatActivity {
Expand Down Expand Up @@ -116,7 +115,8 @@ protected final void onCreate(final Bundle savedInstanceState) {
ButterKnife.bind(this);

if (getIntent().hasExtra(ARG_SESSION_ID)) {
long sessionId = getIntent().getExtras().getLong(ARG_SESSION_ID);
long sessionId = Objects.requireNonNull(
getIntent().getExtras()).getLong(ARG_SESSION_ID);
session = Sessions.getSessionById(sessionId);
}

Expand All @@ -141,12 +141,9 @@ protected final void onCreate(final Bundle savedInstanceState) {

mapView.getZoomController().setVisibility(
CustomZoomButtonsController.Visibility.NEVER);
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
focused = false;
return false;
}
mapView.setOnTouchListener((v, event) -> {
focused = false;
return false;
});

this.initMap(initPosition);
Expand Down
Loading

0 comments on commit 98a7539

Please sign in to comment.