Skip to content

Commit bdbc0b1

Browse files
committed
fix: permission issue while dir creation
1 parent 265189b commit bdbc0b1

13 files changed

+190
-94
lines changed

anyaudio_build2-17_03_02.apk

7.3 MB
Binary file not shown.

app/src/main/java/any/audio/Activity/AnyAudioActivity.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ protected void onCreate(Bundle savedInstanceState) {
169169
private void configureStorageDirectory(Bundle savedInstance) {
170170

171171
if (savedInstance == null) {
172-
L.m("Home configureStorageDirectory()", "making dirs");
173172
AppConfig.getInstance(this).configureDevice();
174173
}
175174
}
@@ -482,7 +481,7 @@ private void handleIntent() {
482481

483482
if (type.equals("search")) {
484483
SharedPrefrenceUtils.getInstance(this).setLastSearchTerm(term);
485-
L.m("AnyAudioHome", " invoking action search");
484+
//L.m(("AnyAudioHome", " invoking action search");
486485
homePanelTitle.setText(reformatHomeTitle(term));
487486
transactFragment(FRAGMENT_SEARCH, term, Constants.SEARCH_MODE_SERVER);
488487
}
@@ -1126,7 +1125,7 @@ public void onReceive(Context context, Intent intent) {
11261125

11271126
if (intent.getAction().equals(Constants.ACTION_STREAM_URL_FETCHED)) {
11281127

1129-
L.m("PlaylistTest", "update via broadcast: streaming uri " + intent.getStringExtra(Constants.EXTRAA_URI));
1128+
//L.m(("PlaylistTest", "update via broadcast: streaming uri " + intent.getStringExtra(Constants.EXTRAA_URI));
11301129

11311130
utils.setStreamUrlFetchedStatus(true);
11321131
String uri = intent.getStringExtra(Constants.EXTRAA_URI);
@@ -1333,7 +1332,7 @@ public void onClick(View view) {
13331332
public void onProgressChanged(SeekBar seekBar, int position, boolean fromUser) {
13341333

13351334
if (fromUser && anyPlayer != null) {
1336-
L.m("Home", "sending seek msg");
1335+
//L.m(("Home", "sending seek msg");
13371336
if (anyPlayer.getBufferedPosition() > position)
13381337
anyPlayer.seekTo(position);
13391338
}
@@ -1413,7 +1412,7 @@ private void resetPlayer() {
14131412
anyPlayer.setPlayWhenReady(false);
14141413
anyPlayer.stop();
14151414
anyPlayer.release();
1416-
L.m("StreamingHome", "Player Reset Done");
1415+
//L.m(("StreamingHome", "Player Reset Done");
14171416

14181417
}
14191418
utils.setPlayerState(Constants.PLAYER.PLAYER_STATE_STOPPED);
@@ -1540,7 +1539,7 @@ private void onNextRequested() {
15401539
//// exoPlayer.setPlayWhenReady(false);
15411540
//// exoPlayer.stop();
15421541
//// exoPlayer.release();
1543-
//// L.m("PlaylistTest", "Player Released");
1542+
//// //L.m(("PlaylistTest", "Player Released");
15441543
//
15451544
// utils.setPlayerState(Constants.PLAYER.PLAYER_STATE_STOPPED);
15461545
// PlaylistItem nxtItem = null;
@@ -1579,7 +1578,7 @@ private void onNextRequested() {
15791578
// diff = anyPlayer.getDuration() - anyPlayer.getCurrentPosition();
15801579
//
15811580
// if (diff > UP_NEXT_PREPARE_TIME_OFFSET) {
1582-
// L.m("PlaylistTest", "diff : " + diff);
1581+
// //L.m(("PlaylistTest", "diff : " + diff);
15831582
// // means stream fetcher not in progress
15841583
// utils.setCurrentItemStreamUrl(upNextVid);
15851584
// utils.setCurrentItemThumbnailUrl(upNextThumbnailUrl);

app/src/main/java/any/audio/Adapters/ExploreLeftToRightAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.support.v7.widget.RecyclerView;
88
import android.util.Log;
9+
import android.util.TypedValue;
910
import android.view.LayoutInflater;
1011
import android.view.MotionEvent;
1112
import android.view.View;
@@ -116,7 +117,8 @@ public ExploreItemCardViewHolder(View itemView, final ArrayList<ItemModel> itemM
116117

117118
int widthPx = (int) SharedPrefrenceUtils.getInstance(context).getScreenWidthPx();
118119
int thumbnailHeight = (int) (0.5 * widthPx);
119-
LinearLayout.LayoutParams thumbnailParams = new LinearLayout.LayoutParams(widthPx-25, thumbnailHeight);
120+
int thumbnail_shift = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, context.getResources().getDisplayMetrics());
121+
LinearLayout.LayoutParams thumbnailParams = new LinearLayout.LayoutParams(widthPx-thumbnail_shift, thumbnailHeight);
120122

121123
thumbnailWrapper.setLayoutParams(thumbnailParams);
122124
cardWrapper.setLayoutParams(new RelativeLayout.LayoutParams(widthPx, ViewGroup.LayoutParams.WRAP_CONTENT));

app/src/main/java/any/audio/Centrals/CentralDataRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static CentralDataRepository getInstance(Context context) {
9898
*/
9999
public void submitAction(final int type, Handler handler) {
100100

101-
L.m("CDR", "Action Invoke Type:" + type);
101+
//L.m(("CDR", "Action Invoke Type:" + type);
102102

103103
this.mHandler = handler;
104104

@@ -129,7 +129,7 @@ public void run() {
129129
}
130130
}.start();
131131

132-
L.m("CDR", "started thread for action");
132+
//L.m(("CDR", "started thread for action");
133133

134134
}
135135
/* get the group title and fetch it from the db and submit
@@ -291,7 +291,7 @@ public void onTrendingLoad(ExploreItemModel trendingItem) {
291291

292292
private void dispatchMessage(int status, String message, ExploreItemModel data) {
293293

294-
L.m("CDR", "dispatching Message");
294+
//L.m(("CDR", "dispatching Message");
295295
Message msg = Message.obtain();
296296
msg.obj = new ResultMessageObjectModel(
297297
status,

app/src/main/java/any/audio/Fragments/DownloadedFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.content.Context;
44
import android.content.DialogInterface;
5+
import android.content.pm.PackageManager;
6+
import android.os.Build;
57
import android.os.Bundle;
68
import android.support.annotation.Nullable;
79
import android.support.v4.app.Fragment;
@@ -134,8 +136,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
134136

135137
}
136138

137-
138139
private ArrayList<DownloadedItemModel> getDownloadedItemList() {
140+
139141
ArrayList<DownloadedItemModel> downloadedItemModels = new ArrayList<>();
140142
File dir = new File(Constants.DOWNLOAD_FILE_DIR);
141143
try {
@@ -155,8 +157,7 @@ private ArrayList<DownloadedItemModel> getDownloadedItemList() {
155157
Log.d("Downloaded", "" + path);
156158
downloadedItemModels.add(0, new DownloadedItemModel(path));
157159
}
158-
}
159-
finally {
160+
} finally {
160161
if (downloadedItemModels.size() == 0) {
161162
emptyMessage.setVisibility(View.VISIBLE);
162163
} else {

app/src/main/java/any/audio/Fragments/NavigationDrawerFragment.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Intent;
55
import android.content.pm.PackageInfo;
66
import android.content.pm.PackageManager;
7+
import android.os.Build;
78
import android.os.Bundle;
89
import android.support.annotation.Nullable;
910
import android.support.v4.app.Fragment;
@@ -73,6 +74,10 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
7374

7475
case 2:
7576

77+
if(!isGrantedPerms()){
78+
return;
79+
}
80+
7681
fragment = AnyAudioActivity.FRAGMENT_DOWNLOADS;
7782
title = "AnyAudio";
7883
break;
@@ -114,6 +119,28 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
114119

115120
}
116121

122+
private boolean canMakeSmores() {
123+
124+
return (Build.VERSION.SDK_INT > Build.VERSION_CODES.M);
125+
126+
}
127+
128+
private boolean isGrantedPerms(){
129+
130+
// Check Permission
131+
String[] perms = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"};
132+
int permsRequestCode = 200;
133+
if (canMakeSmores()) {
134+
if (!(context.checkSelfPermission(perms[0]) == PackageManager.PERMISSION_GRANTED)) {
135+
requestPermissions(perms, permsRequestCode);
136+
}else{
137+
return true;
138+
}
139+
}
140+
141+
return false;
142+
}
143+
117144
private void checkForUpdate() {
118145
Intent i = new Intent(context,UpdateCheckService.class);
119146
i.setAction("ACTION_UPDATE");

app/src/main/java/any/audio/SharedPreferences/SharedPrefrenceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public class SharedPrefrenceUtils {
1515

16-
private static final String PREF_NAME = "musicgenie_tasks";
16+
private static final String PREF_NAME = "anyaudio_tasks";
1717
private static SharedPrefrenceUtils mInstance;
1818
private static int MODE = 0;
1919
private Context context;
Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,60 @@
11
package any.audio.helpers;
22

3-
import android.app.Application;
3+
import android.content.Context;
44
import android.util.Log;
55

6+
import java.io.BufferedWriter;
7+
import java.io.File;
8+
import java.io.FileNotFoundException;
9+
import java.io.FileOutputStream;
10+
import java.io.FileWriter;
11+
import java.io.IOException;
12+
import java.io.OutputStream;
13+
import java.io.OutputStreamWriter;
14+
15+
import any.audio.Config.Constants;
16+
17+
import static android.R.attr.path;
18+
619
/**
720
* Created by Ankit on 9/13/2016.
821
*/
9-
public class L extends Application{
22+
public class L{
23+
24+
private static Context context;
25+
private static L mInstance;
26+
27+
public L(Context context) {
28+
this.context = context;
29+
}
1030

11-
public static void m(String TAG, String m){
12-
Log.d(TAG,m);
31+
public static L getInstance(Context context) {
32+
if (mInstance == null) {
33+
mInstance = new L(context);
34+
}
35+
return mInstance;
1336
}
1437

38+
public void dumpLog(String line){
39+
//
40+
// File dest_dir = new File(Constants.DOWNLOAD_FILE_DIR+"/");
41+
// File dest_file = new File(dest_dir, "log.txt");
42+
//
43+
// Log.d("Dump", "Writing " + line);
44+
// FileWriter fw = null;
45+
// try {
46+
// fw = new FileWriter(dest_file.getAbsoluteFile(), true);
47+
// BufferedWriter bw = new BufferedWriter(fw);
48+
// bw.write(line);
49+
// } catch (IOException e) {
50+
// e.printStackTrace();
51+
// }
52+
53+
54+
}
55+
56+
57+
public static void m(String dbHelper, String s) {
58+
Log.d(dbHelper,s);
59+
}
1560
}

app/src/main/java/any/audio/helpers/QueueManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,15 @@ public ArrayList<PlaylistItem> getQueue() {
133133

134134
ArrayList<PlaylistItem> playlistItems = new ArrayList<>();
135135

136+
136137
PlaylistItem upNextItem = null;
137138
videoTitles = new Segmentor().getParts(utils.getQueueTitles(), '#');
138139
videoIds = new Segmentor().getParts(utils.getQueueVideoId(), '#');
139140
youtubeIds = new Segmentor().getParts(utils.getQueueYoutubeIds(), '#');
140141
uploadersList = new Segmentor().getParts(utils.getQueueUploaders(), '#');
141142

143+
// Add the last played item as the first item of the queue
144+
142145
for (int i = 0; i < videoIds.size(); i++) {
143146
upNextItem = new PlaylistItem(videoIds.get(i), youtubeIds.get(i), videoTitles.get(i), uploadersList.get(i));
144147
playlistItems.add(upNextItem);

app/src/main/java/any/audio/helpers/StreamUrlFetcher.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public StreamUrlFetcher setData(String v_id, String file_name) {
5757
}
5858

5959
public void initProcess() {
60-
//new StreamThread(this.vid, this.file).start();
60+
6161
requestStreamUrlUsingVolley(this.vid);
62-
L.m("StreamUrlFetcher", " Thread Started: stream uri fetch");
62+
L.m("DuplicateTest", " Thread Started: stream uri fetch");
63+
6364
}
6465

6566
private void broadcastURI(String t_url, String file) {
@@ -88,23 +89,23 @@ private void requestStreamUrlUsingVolley(final String v_id) {
8889

8990
try {
9091
VolleyUtils.getInstance().cancelPendingRequests(STREAM_URL_REQUEST_TAG_VOLLEY);
91-
Log.d("StreamUrlFetcher", " Cancellig Pending Volley Requests For Stream Url");
92+
Log.d("DuplicateTest", " Cancellig Pending Volley Requests For Stream Url");
9293

9394
} catch (Exception e) {
94-
Log.d("StreamUrlFetcher", " Attempt To Cancel NoRequests");
95+
Log.d("DuplicateTest", " Attempt To Cancel NoRequests");
9596
}
9697

9798
final String streaming_url_pref = URLS.URL_SERVER_ROOT;
9899
String url = URLS.URL_SERVER_ROOT + "api/v1/stream?url=" + v_id;
99-
Log.d("StreamUrlFetcher"," requesting url for stream on:"+url) ;
100+
Log.d("DuplicateTest"," requesting url for stream on:"+url) ;
100101
StringRequest updateCheckReq = new StringRequest(
101102
Request.Method.GET,
102103
url,
103104
new Response.Listener<String>() {
104105
@Override
105106
public void onResponse(String result) {
106107

107-
Log.d("StreamUrlFetcher"," response "+result) ;
108+
Log.d("DuplicateTest"," response "+result) ;
108109

109110
JSONObject obj = null;
110111
try {
@@ -130,7 +131,7 @@ public void onResponse(String result) {
130131
new Response.ErrorListener() {
131132
@Override
132133
public void onErrorResponse(VolleyError volleyError) {
133-
Log.d("StreamUrlFetcher", " VolleyError " + volleyError);
134+
Log.d("DuplicateTest", " VolleyError " + volleyError);
134135
broadcastURI(Constants.STREAM_PREPARE_FAILED_URL_FLAG, file);
135136
}
136137
});
@@ -141,6 +142,7 @@ public void onErrorResponse(VolleyError volleyError) {
141142
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
142143

143144
VolleyUtils.getInstance().addToRequestQueue(updateCheckReq, STREAM_URL_REQUEST_TAG_VOLLEY, context);
145+
144146
}
145147

146148
}

0 commit comments

Comments
 (0)