Skip to content

Commit

Permalink
added in app review feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-atul committed Sep 12, 2022
1 parent ab60bf1 commit f01eed5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Join the community of discord!
- [x] Removed default track ordering for albums (so for all songs at initial stage)
- [x] Add auto list updates and setting updates without restart
- [x] Changed Folder selection dialog ui, and bug fixes
- [x] Add Store In-Review for the app
- [ ] Add feature to edit the filename (or include in tag editor?)
- [ ] Support API version 33 (multiple api changes to do)
- [ ] Complete Material Design ?
Expand Down
6 changes: 4 additions & 2 deletions src/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.atul.musicplayer"
minSdkVersion 23
targetSdkVersion 30
versionCode 6
versionName "0.6"
versionCode 7
versionName "0.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -53,6 +53,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.google.android.play:review:2.0.0'

implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation 'com.google.code.gson:gson:2.8.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.atul.musicplayer.App;
import com.atul.musicplayer.MPConstants;
import com.atul.musicplayer.MPPreferences;
import com.atul.musicplayer.R;
Expand All @@ -25,8 +26,12 @@
import com.atul.musicplayer.model.Folder;
import com.atul.musicplayer.viewmodel.MainViewModel;
import com.atul.musicplayer.viewmodel.MainViewModelFactory;
import com.google.android.gms.tasks.Task;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.play.core.review.ReviewInfo;
import com.google.android.play.core.review.ReviewManager;
import com.google.android.play.core.review.ReviewManagerFactory;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -43,6 +48,9 @@ public class SettingsFragment extends Fragment implements View.OnClickListener {
private MaterialToolbar toolbar;
private FolderDialog folderDialog;

private ReviewManager reviewManager;
private ReviewInfo reviewInfo;

public SettingsFragment() {
}

Expand Down Expand Up @@ -98,9 +106,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
view.findViewById(R.id.night_chip).setOnClickListener(this);
view.findViewById(R.id.light_chip).setOnClickListener(this);
view.findViewById(R.id.auto_chip).setOnClickListener(this);
view.findViewById(R.id.review_options).setOnClickListener(this);

setUpOptions();

reviewManager = ReviewManagerFactory.create(App.getContext());
Task<ReviewInfo> request = reviewManager.requestReviewFlow();
request.addOnCompleteListener(task -> {
if(task.isSuccessful()) {
reviewInfo = task.getResult();
}
});

return view;

}
Expand Down Expand Up @@ -167,6 +184,10 @@ else if (id == R.id.folder_options)
else if (id == R.id.refresh_options) {
refreshMediaLibrary();
}

else if (id == R.id.review_options) {
setUpRateReview();
}
}

@Override
Expand Down Expand Up @@ -201,4 +222,14 @@ private void setAlbumRequest() {
MPPreferences.storeAlbumRequest(requireActivity().getApplicationContext(), (!state));
ThemeHelper.applySettings(getActivity());
}

private void setUpRateReview () {
if(reviewInfo == null) {
Toast.makeText(getContext(), "Review service is not yet available", Toast.LENGTH_SHORT).show();
return;
}

Task<Void> flow = reviewManager.launchReviewFlow(requireActivity(), reviewInfo);
flow.addOnCompleteListener(task -> {});
}
}
5 changes: 5 additions & 0 deletions src/app/src/main/res/drawable/ic_rate_review.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM6,14v-2.47l6.88,-6.88c0.2,-0.2 0.51,-0.2 0.71,0l1.77,1.77c0.2,0.2 0.2,0.51 0,0.71L8.47,14L6,14zM18,14h-7.5l2,-2L18,12v2z"/>
</vector>
46 changes: 46 additions & 0 deletions src/app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,52 @@

</LinearLayout>

<LinearLayout
android:id="@+id/review_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="10dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/image"
android:src="@drawable/ic_rate_review"
app:tint="?colorPrimary" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/nunito_sans"
android:text="@string/rate_title"
android:textColor="@color/colorTextHigh"
android:textSize="@dimen/text_big" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/nunito_sans"
android:text="@string/rate_subtitle"
android:textColor="@color/colorTextMed"
android:textSize="@dimen/text_big_med" />

</LinearLayout>

</LinearLayout>

</LinearLayout>
</RelativeLayout>
Expand Down
2 changes: 2 additions & 0 deletions src/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<string name="zero_time">00:00</string>
<string name="refresh_title">Refresh media library for new content</string>
<string name="refresh_subtitle">we look into every corner for some new tunes you got</string>
<string name="rate_title">Rate the app</string>
<string name="rate_subtitle">let everyone know what you feel about the app</string>
<string name="options">OPTIONS</string>
<string name="add_to_playlist">Add to playlist</string>
<string name="playlists">PLAYLISTS</string>
Expand Down

0 comments on commit f01eed5

Please sign in to comment.