Skip to content

Commit

Permalink
In-App downloader (#52)
Browse files Browse the repository at this point in the history
* Added aria2lib submodule

* Basic implementation

* Renamed thing

* Updated thing

* Updated deps

* Updated submodules

* Fixed conflicts

* Started implementation

* Working prototype!

* Removed old Aria2Android logic + some strings

* Added configuration screen

* Exit if service is stopped

* Completed configuration activity

* Open correct profile if aria2 notification is used

* Implemented custom options

* Start at boot + upgrade app message

* Minor UI stuff
  • Loading branch information
devgianlu authored Apr 26, 2019
1 parent fca68ac commit c98f8a1
Show file tree
Hide file tree
Showing 69 changed files with 809 additions and 384 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
path = Android--Library-Country-Flags
url = https://github.com/devgianlu/Android--Library-Country-Flags
branch = master
[submodule "aria2lib"]
path = aria2lib
url = https://github.com/devgianlu/aria2lib
branch = master
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ android {
dependencies {
api project(':CommonUtils')
api project(':CountryFlags')
api project(':aria2lib')
api 'com.tonyodev.fetch2:fetch2:3.0.4'
api 'com.tonyodev.fetch2okhttp:fetch2okhttp:3.0.4'
api 'com.squareup.okhttp3:okhttp:3.14.0'
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<!-- Loading activity -->
<activity
android:name=".LoadingActivity"
android:noHistory="true"
android:theme="@style/FullscreenTheme">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -138,6 +138,12 @@
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden" />

<!-- In-App downloader configuration activity -->
<activity
android:name=".InAppAria2.InAppAria2ConfActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />

<!-- DirectDownload activity -->
<activity
android:name=".Activities.DirectDownloadActivity"
Expand Down Expand Up @@ -218,4 +224,5 @@
android:resource="@xml/logs_paths" />
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gianlu.aria2app.Adapters.OptionsAdapter;
import com.gianlu.aria2app.NetIO.AbstractClient;
import com.gianlu.aria2app.NetIO.Aria2.Aria2Helper;
Expand All @@ -34,9 +37,6 @@
import java.util.List;
import java.util.Set;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class OptionsFragment extends FragmentWithDialog implements OptionsAdapter.Listener {
private EditText position;
private EditText filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gianlu.aria2app.Adapters.UrisAdapter;
import com.gianlu.aria2app.R;
import com.gianlu.commonutils.Dialogs.FragmentWithDialog;
Expand All @@ -24,13 +31,6 @@
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


public class UrisFragment extends FragmentWithDialog implements UrisAdapter.Listener {
private UrisAdapter adapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.gianlu.aria2app.Adapters.DirectDownloadsAdapter;
import com.gianlu.aria2app.NetIO.Downloader.FetchHelper;
import com.gianlu.aria2app.R;
Expand All @@ -19,10 +23,6 @@

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

public class DirectDownloadActivity extends ActivityWithDialog implements FetchHelper.FetchEventListener {
private RecyclerViewLayout layout;
private FetchHelper helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import android.widget.RadioGroup;
import android.widget.ScrollView;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gianlu.aria2app.NetIO.AbstractClient;
import com.gianlu.aria2app.ProfilesManager.MultiProfile;
import com.gianlu.aria2app.R;
import com.gianlu.commonutils.CommonUtils;
import com.google.android.material.textfield.TextInputLayout;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class AuthenticationFragment extends FieldErrorFragment {
private ScrollView layout;
private RadioGroup authMethod;
Expand Down Expand Up @@ -148,13 +148,13 @@ public Fields getFields(Context context) throws InvalidFieldException {
return new Fields(authMethod, token, username, password);
}

public class Fields {
public static class Fields {
public final AbstractClient.AuthMethod authMethod;
public final String token;
public final String username;
public final String password;

Fields(AbstractClient.AuthMethod authMethod, @Nullable String token, @Nullable String username, @Nullable String password) {
public Fields(AbstractClient.AuthMethod authMethod, @Nullable String token, @Nullable String username, @Nullable String password) {
this.authMethod = authMethod;
this.token = token;
this.username = username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import android.widget.ImageButton;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.gianlu.aria2app.NetIO.CertUtils;
import com.gianlu.aria2app.R;
import com.gianlu.aria2app.Utils;
Expand All @@ -30,12 +36,6 @@

import javax.security.auth.x500.X500Principal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

public class CertificateInputView extends LinearLayout {
public static final int CODE_PICK_CERT = 13;
private LinearLayout detailsContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gianlu.aria2app.CountryFlags;
import com.gianlu.aria2app.NetIO.Geolocalization.GeoIP;
import com.gianlu.aria2app.NetIO.Geolocalization.IPDetails;
Expand All @@ -31,10 +35,6 @@
import java.util.Timer;
import java.util.TimerTask;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class ConnectionFragment extends FieldErrorFragment implements CertificateInputView.ActivityProvider {
private final CountryFlags flags = CountryFlags.get();
private ScrollView layout;
Expand Down Expand Up @@ -275,7 +275,7 @@ public void onFieldError(@IdRes int fieldId, String reason) {
}
}

public class Fields {
public static class Fields {
public final MultiProfile.ConnectionMethod connectionMethod;
public final String address;
public final int port;
Expand All @@ -284,7 +284,7 @@ public class Fields {
public final X509Certificate certificate;
public final boolean hostnameVerifier;

Fields(MultiProfile.ConnectionMethod connectionMethod, String address, int port, String endpoint, boolean encryption, @Nullable X509Certificate certificate, boolean hostnameVerifier) {
public Fields(MultiProfile.ConnectionMethod connectionMethod, String address, int port, String endpoint, boolean encryption, @Nullable X509Certificate certificate, boolean hostnameVerifier) {
this.connectionMethod = connectionMethod;
this.address = address;
this.port = port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import android.widget.LinearLayout;
import android.widget.ScrollView;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.gianlu.aria2app.ProfilesManager.MultiProfile;
import com.gianlu.aria2app.R;
import com.gianlu.commonutils.AskPermission;
Expand All @@ -21,11 +26,6 @@

import java.net.URL;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

public class DirectDownloadFragment extends FieldErrorFragment implements CertificateInputView.ActivityProvider {
private ScrollView layout;
private CheckBox enableDirectDownload;
Expand Down Expand Up @@ -171,10 +171,10 @@ public void onFieldError(@IdRes int fieldId, String reason) {
}
}

public class Fields {
public static class Fields {
public final MultiProfile.DirectDownload dd;

Fields(@Nullable MultiProfile.DirectDownload dd) {
public Fields(@Nullable MultiProfile.DirectDownload dd) {
this.dd = dd;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import android.widget.LinearLayout;
import android.widget.ScrollView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gianlu.aria2app.ProfilesManager.MultiProfile;
import com.gianlu.aria2app.ProfilesManager.Testers.BaseTester;
import com.gianlu.aria2app.ProfilesManager.Testers.TestersFlow;
import com.gianlu.aria2app.R;
import com.gianlu.commonutils.SuperTextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class TestFragment extends Fragment implements TestersFlow.ITestFlow {
private OnGetProfile listener;
private LinearLayout testResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
import android.widget.RadioGroup;
import android.widget.Spinner;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.gianlu.aria2app.Activities.EditProfile.AuthenticationFragment;
import com.gianlu.aria2app.Activities.EditProfile.ConnectionFragment;
import com.gianlu.aria2app.Activities.EditProfile.DirectDownloadFragment;
Expand Down Expand Up @@ -46,13 +53,6 @@
import java.util.List;
import java.util.Objects;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

public class EditProfileActivity extends ActivityWithDialog implements TestFragment.OnGetProfile {
private MultiProfile editProfile;
private TextInputLayout profileName;
Expand Down Expand Up @@ -325,9 +325,9 @@ private void refreshSpinner() {
@Nullable
private MultiProfile buildProfile() throws InvalidFieldException { // FIXME: Returns null when messing up with conditions
String profileName = CommonUtils.getText(this.profileName).trim();
if (profileName.isEmpty() ||
(ProfilesManager.get(this).profileExists(ProfilesManager.getId(profileName))
&& editProfile == null)) {
if (profileName.isEmpty()
|| (ProfilesManager.get(this).profileExists(ProfilesManager.getId(profileName)) && editProfile == null)
|| profileName.equals(MultiProfile.IN_APP_DOWNLOADER_NAME)) {
throw new InvalidFieldException(MainActivity.class, R.id.editProfile_profileName, getString(R.string.invalidProfileName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentActivity;

import com.gianlu.aria2app.FileTypeTextView;
import com.gianlu.aria2app.NetIO.AbstractClient;
import com.gianlu.aria2app.NetIO.Aria2.AriaFile;
Expand All @@ -28,11 +33,6 @@

import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentActivity;

public class FileSheet extends ThemedModalBottomSheet<FileSheet.SetupPayload, AriaFiles> {
private TextView percentage;
private int fileIndex = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ActionMode;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.gianlu.aria2app.Activities.DirectDownloadActivity;
import com.gianlu.aria2app.Activities.MoreAboutDownload.BigUpdateProvider;
import com.gianlu.aria2app.Activities.MoreAboutDownload.OnBackPressed;
Expand Down Expand Up @@ -54,13 +62,6 @@
import java.util.Collections;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ActionMode;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import okhttp3.HttpUrl;

public class FilesFragment extends UpdaterFragment<DownloadWithUpdate.BigUpdate> implements TutorialManager.Listener, FilesAdapter.Listener, OnBackPressed, FileSheet.Listener, DirectorySheet.Listener, BreadcrumbsView.Listener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.gianlu.aria2app.Activities.MoreAboutDownload.BigUpdateProvider;
import com.gianlu.aria2app.Activities.MoreAboutDownload.OnBackPressed;
import com.gianlu.aria2app.Adapters.BitfieldVisualizer;
Expand Down Expand Up @@ -40,10 +44,6 @@
import java.util.Date;
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

public class InfoFragment extends UpdaterFragment<DownloadWithUpdate.BigUpdate> implements OnBackPressed, Aria2Helper.DownloadActionClick.Listener {
private final CountryFlags flags = CountryFlags.get();
private final GeoIP geoIP = GeoIP.get();
Expand Down
Loading

0 comments on commit c98f8a1

Please sign in to comment.