Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Cosgrove committed Nov 28, 2017
2 parents cdb53c5 + ac98bce commit 7b2add6
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

ext.versionMajor = 1
ext.versionMinor = 1
ext.versionMinor = 2
ext.versionPatch = 0
ext.versionClassifier = null
ext.isSnapshot = false
Expand All @@ -18,6 +18,12 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "NowPlayingHistory-v$versionName($versionCode)")
}
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":260010100},"path":"NowPlayingHistory-v1.1.0(260010100)-release.apk","properties":{"packageId":"io.cosgrove.nowplaying_history","split":"","minSdkVersion":"26"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":260010200},"path":"NowPlayingHistory-v1.2.0(260010200)-release.apk","properties":{"packageId":"io.cosgrove.nowplaying_history","split":"","minSdkVersion":"26"}}]
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:fullBackupContent="@xml/backup_descriptor">
<service
android:name="io.cosgrove.nowplaying_history.services.NLService"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ protected void onCreate(Bundle savedInstanceState) {
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);

// get dataset
List<SongHistory> songHistoryList = SongHistoryStore.get(this).getSongHistory();

// specify an adapter
mAdapter = new SongHistoryAdapter(songHistoryList);
mAdapter = new SongHistoryAdapter(SongHistoryStore.get(this));
mRecyclerView.setAdapter(mAdapter);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.cosgrove.nowplaying_history;

import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.provider.MediaStore;
import android.support.v7.widget.RecyclerView;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -10,6 +15,7 @@

import io.cosgrove.nowplaying_history.models.SongHistory;
import io.cosgrove.nowplaying_history.utils.DateHelper;
import io.cosgrove.nowplaying_history.utils.SongHistoryStore;

/*
Created by Tyler Cosgrove (vivalldi) on 10/31/17.
Expand All @@ -30,33 +36,66 @@ Created by Tyler Cosgrove (vivalldi) on 10/31/17.

public class SongHistoryAdapter extends RecyclerView.Adapter<SongHistoryAdapter.ViewHolder> {
private List<SongHistory> mDataset;
private SongHistoryStore mSongHistoryStore;
private Context context;

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class ViewHolder extends RecyclerView.ViewHolder {
public class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, View.OnLongClickListener{
public View mView;
public TextView mTitleTextView;
public TextView mArtistTextView;
public TextView mTimestampTextView;
public ViewHolder(View v) {
super(v);
context = v.getContext();
v.setOnClickListener(this);
v.setOnLongClickListener(this);
mView = v;
mTitleTextView = (TextView) v.findViewById(R.id.song_title);
mArtistTextView = (TextView) v.findViewById(R.id.song_artist);
mTimestampTextView = (TextView) v.findViewById(R.id.song_timestamp);

}
@Override
public void onClick(View view) {
String artist = (String) mArtistTextView.getText();
String title = (String) mTitleTextView.getText();
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
"vnd.android.cursor.item/audio");
intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, title);
intent.putExtra(SearchManager.QUERY, title);
if(intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
}
}
@Override
public boolean onLongClick(View view) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
removeItem(getAdapterPosition());
return true;
}
}
// Constructor
public SongHistoryAdapter(List<SongHistory> dataset) {
mDataset = dataset;
public SongHistoryAdapter(SongHistoryStore songHistoryStore) {
mSongHistoryStore = songHistoryStore;
mDataset = songHistoryStore.getSongHistory();
}

public void setDataset(List<SongHistory> updatedDataset) {
this.mDataset = updatedDataset;
}

public void removeItem(int position) {
mSongHistoryStore.deleteSongHistory(mDataset.get(position));
mDataset.remove(position);
notifyItemRemoved(position);
}

// Create new views (called by layout manager)
@Override
public SongHistoryAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Expand All @@ -76,7 +115,7 @@ public void onBindViewHolder(ViewHolder holder, int position) {
SongHistory currentSong = mDataset.get(position);
holder.mTitleTextView.setText(currentSong.getSongTitle());
holder.mArtistTextView.setText(currentSong.getSongArtist());
holder.mTimestampTextView.setText(DateHelper.changeISOToShortTime12(currentSong.getSongHeardDate()));
holder.mTimestampTextView.setText(DateHelper.generateUITimestamp(currentSong.getSongHeardDate()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d("DB_UPGRADE", "Updating " + SongHistoryTable.NAME + " tabel to version " +
Log.d("DB_UPGRADE", "Updating " + SongHistoryTable.NAME + " table to version " +
newVersion +" from version " + oldVersion);

Cursor cursor = db.query(SongHistoryTable.NAME, null, null, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class DateHelper {
public static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
public static final String SHORT_TIME_12_FORMAT = "h:mm a";
public static final String SHORT_TIME_24_FORMAT = "HH:mm";
public static final String SHORT_MONTH_DATE = "MMM dd";

private static String formatDate(Date date, String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.US);
Expand Down Expand Up @@ -92,4 +93,22 @@ public static String changeISOToShortTime24(String timestamp) {
public static String changeISOToShortTime12(String timestamp) {
return changeFormat(timestamp, ISO_8601_FORMAT, SHORT_TIME_12_FORMAT);
}

public static String generateUITimestamp(String iso) {
String timestamp = null;
SimpleDateFormat isoSDF = new SimpleDateFormat(ISO_8601_FORMAT, Locale.US);
try {
Date date = isoSDF.parse(iso);
Date now = new Date();
if (Math.abs(date.getTime() - now.getTime()) > 24 * 60 * 60 * 1000L) {
timestamp = changeFormat(iso, ISO_8601_FORMAT, SHORT_MONTH_DATE);
} else {
timestamp = changeISOToShortTime12(iso);
}

} catch (ParseException e) {
Log.wtf("DateHelper", "Unable to parse date: " + e.getMessage());
}
return timestamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,13 @@ private SongHistoryStore(Context context) {
public List<SongHistory> getSongHistory() {
List<SongHistory> songHistories = new ArrayList<>();

SongHistoryCursorWrapper cursor = querySongHistories(null, null, SongHistoryTable.Cols.SONG_HEARD_DATE + " DESC");

try {
try (SongHistoryCursorWrapper cursor = querySongHistories(null, null, SongHistoryTable.Cols.SONG_HEARD_DATE + " DESC")) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
SongHistory songHistory = cursor.getSongHistory();
songHistories.add(songHistory);
cursor.moveToNext();
}
} finally {
cursor.close();
}

Collections.sort(songHistories, new Comparator<SongHistory>() {
Expand Down Expand Up @@ -104,7 +100,10 @@ public Integer size() {
String countQuery = "SELECT * FROM " + SongHistoryTable.NAME;
Cursor cursor = mDatabase.rawQuery(countQuery, null);

return cursor.getCount();
Integer count = cursor.getCount();
cursor.close();

return count;
}


Expand Down
34 changes: 0 additions & 34 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

2 changes: 2 additions & 0 deletions app/src/main/res/layout/song_history_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
android:id="@+id/song_history_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:orientation="vertical">

<TextView
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/layout/song_history_item_relative.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:id="@+id/song_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:clickable="false"
android:duplicateParentState="true"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
Expand All @@ -25,6 +26,7 @@
android:id="@+id/song_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:lines="1"
android:textColor="@color/title"
android:textSize="16sp"
Expand All @@ -34,6 +36,7 @@
android:id="@+id/song_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:lines="1"
android:textColor="@color/artist"
android:textSize="14sp"
Expand All @@ -48,8 +51,9 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:duplicateParentState="true"
android:textColor="@color/timestamp"
android:textSize="12dp"
android:textSize="12sp"
android:textStyle="bold"
tools:text="10:30 AM" />

Expand Down
Empty file added app/src/main/res/mipmap-anydpi
Empty file.
8 changes: 8 additions & 0 deletions app/src/main/res/xml/backup_descriptor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- TODO Remove the following "exclude" elements to make them a part of the auto backup -->
<exclude
domain="database"
path="SongHistory.db" />
<!-- Exclude specific shared preferences that contain GCM registration Id -->
</full-backup-content>

0 comments on commit 7b2add6

Please sign in to comment.