Skip to content

Commit

Permalink
Added data downloads to CBPS-DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Electric1447 committed Jun 8, 2020
1 parent 37f29d0 commit 664fa2d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "eparon.vhbb_android"
minSdkVersion 21
targetSdkVersion 29
versionCode 8
versionName "beta-6"
versionCode 9
versionName "beta-7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "en"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void onBindViewHolder (@NonNull CBPSDBAdapter.ViewHolder holder, int posi
String urlID = currentItem.getUrl();
String optionsID = currentItem.getOptions();
String typeID = currentItem.getType();
String dataUrlID = currentItem.getDataUrl();

holder.mTitle.setText(nameID);
holder.mAuthor.setText(authorID);
Expand Down Expand Up @@ -122,6 +123,35 @@ public void onBindViewHolder (@NonNull CBPSDBAdapter.ViewHolder holder, int posi
assert downloadmanager != null;
downloadmanager.enqueue(request);
});

holder.mDownloadData.setVisibility(!dataUrlID.equals("None") ? View.VISIBLE : View.GONE);

if (!dataUrlID.equals("None")) holder.mDownloadData.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(v.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
PermissionUtils.requestStoragePermission(mActivity);

if (!NetworkUtils.isNetworkAvailable(v.getContext())) {
Toast.makeText(v.getContext(), "Network not available", Toast.LENGTH_SHORT).show();
return;
}

DownloadManager downloadmanager = (DownloadManager)v.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(dataUrlID);

String filename = urlID.substring(urlID.lastIndexOf("/") + 1);
filename = filename.substring(0, filename.lastIndexOf(".")) + "-data.zip";

DownloadManager.Request request = new DownloadManager.Request(uri)
.setTitle(filename)
.setDescription("Downloading...")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setVisibleInDownloadsUi(true)
.addRequestHeader(VitaDB.UA_REQUEST_HEADER, VitaDB.UA_REQUEST_VALUE) // Set a valid user-agent for the requests.
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);

assert downloadmanager != null;
downloadmanager.enqueue(request);
});
}

@Override
Expand All @@ -131,7 +161,7 @@ public int getItemCount () {

public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTitle, mAuthor, mType;
public ImageButton mDownload;
public ImageButton mDownload, mDownloadData;
public ImageView mIcon;

public ViewHolder (View itemView) {
Expand All @@ -140,6 +170,7 @@ public ViewHolder (View itemView) {
mAuthor = itemView.findViewById(R.id.textview_author);
mType = itemView.findViewById(R.id.textview_type);
mDownload = itemView.findViewById(R.id.download);
mDownloadData = itemView.findViewById(R.id.downloadData);
mIcon = itemView.findViewById(R.id.image);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;

import androidx.annotation.NonNull;
Expand All @@ -34,6 +33,7 @@

public class CBPSDBFragment extends Fragment {

private static final String TAG = "VHBB-Android";
private RecyclerView mRecyclerView;
private CBPSDBAdapter mCBPSDBAdapter;
private ArrayList<CBPSDBItem> mCBPSDBList;
Expand Down Expand Up @@ -117,15 +117,26 @@ private List<String[]> downloadRemoteTextFileContent () {
}

private void initializeAdapter (List<String[]> result) {
List<String[]> dataList = new ArrayList<>();

for (int i = 1; i < result.size(); i++) {
String[] item = result.get(i);

boolean isVisible = item[CBPSDB.CVS_VISIBLE].equalsIgnoreCase("true");
boolean isVisible = item[CBPSDB.CVS_VISIBLE].equals("True");

if (isVisible)
if (isVisible) {
mCBPSDBList.add(new CBPSDBItem(item[CBPSDB.CVS_ID], item[CBPSDB.CVS_TITLE], item[CBPSDB.CVS_CREDITS], item[CBPSDB.CVS_ICON0], item[CBPSDB.CVS_URL], item[CBPSDB.CVS_OPTIONS], item[CBPSDB.CVS_TYPE]));
} else {
dataList.add(new String[] {item[CBPSDB.CVS_TITLE].substring(0, item[CBPSDB.CVS_TITLE].length() - 11), item[CBPSDB.CVS_URL]});
}
}

if (dataList.size() > 0)
for (int i = 0; i < dataList.size(); i++)
for (int j = 0; j < mCBPSDBList.size(); j++)
if (dataList.get(i)[0].equals(mCBPSDBList.get(j).getName()))
mCBPSDBList.get(j).setDataUrl(dataList.get(i)[1]);

mCBPSDBAdapter = new CBPSDBAdapter(requireActivity(), mCBPSDBList);
mRecyclerView.setAdapter(mCBPSDBAdapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CBPSDBItem {
private String Url;
private String Options;
private String Type;
private String DataUrl = "None";

public CBPSDBItem (String id, String name, String author, String icon0, String url, String options, String type) {
this.ID = id;
Expand Down Expand Up @@ -73,4 +74,12 @@ public String getTypeString () {
}
}

public String getDataUrl () {
return DataUrl;
}

public void setDataUrl (String dataUrl) {
DataUrl = dataUrl;
}

}
14 changes: 0 additions & 14 deletions app/src/main/res/layout/item_cbpsdb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />

<TextView
android:id="@+id/textview_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview_author"
android:layout_alignParentLeft="true"
android:layout_marginRight="@dimen/homebrew_desc_margin_def"
android:maxLines="3"
android:paddingTop="@dimen/homebrew_padding_small"
android:text="Descriptions Currently Unsupported"
android:textSize="@dimen/text_description"
android:textStyle="italic"
android:tint="@color/textColorDescription" />

</RelativeLayout>

</LinearLayout>
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

0 comments on commit 664fa2d

Please sign in to comment.