Delete TransferService revert to native DL/UP
This commit is contained in:
		@ -1,58 +0,0 @@
 | 
			
		||||
package com.localtransfer;
 | 
			
		||||
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.os.Parcel;
 | 
			
		||||
import android.os.Parcelable;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
public class Extra implements Parcelable {
 | 
			
		||||
 | 
			
		||||
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
 | 
			
		||||
        public Extra createFromParcel(Parcel in) {
 | 
			
		||||
            return new Extra(in);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Extra[] newArray(int size) {
 | 
			
		||||
            return new Extra[size];
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    public String name;
 | 
			
		||||
    public long size;
 | 
			
		||||
    public String href;
 | 
			
		||||
    public String uri;
 | 
			
		||||
    public int id;
 | 
			
		||||
 | 
			
		||||
    // Constructor
 | 
			
		||||
    public Extra(Uri uri, String name, long size, String href, View view){
 | 
			
		||||
        this.uri = uri.toString();
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.size = size;
 | 
			
		||||
        this.href = href;
 | 
			
		||||
        this.id = view.getId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Parcelling part
 | 
			
		||||
    public Extra(Parcel in){
 | 
			
		||||
        this.uri = in.readString();
 | 
			
		||||
        this.name = in.readString();
 | 
			
		||||
        this.size = in.readLong();
 | 
			
		||||
        this.href = in.readString();
 | 
			
		||||
        this.id = in.readInt();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int describeContents() {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void writeToParcel(Parcel dest, int flags) {
 | 
			
		||||
        dest.writeString(this.uri);
 | 
			
		||||
        dest.writeString(this.name);
 | 
			
		||||
        dest.writeLong(this.size);
 | 
			
		||||
        dest.writeString(this.href);
 | 
			
		||||
        dest.writeInt(this.id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,75 +0,0 @@
 | 
			
		||||
package com.localtransfer;
 | 
			
		||||
 | 
			
		||||
import android.app.IntentService;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.widget.Button;
 | 
			
		||||
import android.widget.LinearLayout;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
public class TransferService extends IntentService {
 | 
			
		||||
 | 
			
		||||
    public static final String ACTION_UPLOAD = "com.localtransfer.action.FOO";
 | 
			
		||||
    public static final String ACTION_DOWNLOAD = "com.localtransfer.action.BAZ";
 | 
			
		||||
 | 
			
		||||
    public static final String EXTRA_URI = "com.localtransfer.extra.URI";
 | 
			
		||||
    public static final String EXTRA = "com.localtransfer.extra.EXTRA";
 | 
			
		||||
 | 
			
		||||
    public TransferService() {
 | 
			
		||||
        super("TransferService");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onHandleIntent(Intent intent) {
 | 
			
		||||
        if (intent != null) {
 | 
			
		||||
            final String action = intent.getAction();
 | 
			
		||||
            switch (action) {
 | 
			
		||||
                case ACTION_UPLOAD:
 | 
			
		||||
                    handleUpload(intent);
 | 
			
		||||
                    break;
 | 
			
		||||
                case ACTION_DOWNLOAD:
 | 
			
		||||
                    handleDownload(intent);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void handleUpload(Intent intent) {
 | 
			
		||||
        final Uri uri = intent.getParcelableExtra(EXTRA_URI);
 | 
			
		||||
 | 
			
		||||
        Transfer tr = new Transfer();
 | 
			
		||||
        try {
 | 
			
		||||
            tr.uploadFile(uri);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            final String ExceptionName = e.getClass().getSimpleName();
 | 
			
		||||
            final String ExceptionMess = e.getMessage();
 | 
			
		||||
 | 
			
		||||
            if(ExceptionName != null && ExceptionMess != null) {
 | 
			
		||||
                Transfer.error(ExceptionName + ": " + ExceptionMess, null, null);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void handleDownload(Intent intent) {
 | 
			
		||||
        Extra ex = (Extra) intent.getExtras().getParcelable(EXTRA);
 | 
			
		||||
        final LinearLayout layout = Transfer.activity.findViewById(ex.id);
 | 
			
		||||
        Button button = null;
 | 
			
		||||
        if(layout != null)
 | 
			
		||||
            button = layout.findViewById(R.id.file_download);
 | 
			
		||||
 | 
			
		||||
        Transfer tr = new Transfer();
 | 
			
		||||
        try {
 | 
			
		||||
            tr.downloadFile(Uri.parse(ex.uri), ex.name, ex.size, ex.href, button);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            final String ExceptionName = e.getClass().getSimpleName();
 | 
			
		||||
            final String ExceptionMess = e.getMessage();
 | 
			
		||||
 | 
			
		||||
            if(ExceptionName != null && ExceptionMess != null) {
 | 
			
		||||
                Transfer.error(ExceptionName + ": " + ExceptionMess, null, null);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -12,8 +12,6 @@ import androidx.fragment.app.Fragment;
 | 
			
		||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 | 
			
		||||
 | 
			
		||||
import android.os.Environment;
 | 
			
		||||
import android.os.Parcelable;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.ContextMenu;
 | 
			
		||||
import android.view.Gravity;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
@ -23,18 +21,15 @@ import android.view.ViewGroup;
 | 
			
		||||
import android.view.animation.Animation;
 | 
			
		||||
import android.view.animation.LinearInterpolator;
 | 
			
		||||
import android.widget.Button;
 | 
			
		||||
import android.widget.FrameLayout;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.LinearLayout;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
import com.google.android.material.snackbar.Snackbar;
 | 
			
		||||
import com.localtransfer.BuildConfig;
 | 
			
		||||
import com.localtransfer.Extra;
 | 
			
		||||
import com.localtransfer.Progress;
 | 
			
		||||
import com.localtransfer.R;
 | 
			
		||||
import com.localtransfer.Transfer;
 | 
			
		||||
import com.localtransfer.TransferService;
 | 
			
		||||
 | 
			
		||||
import org.json.JSONArray;
 | 
			
		||||
import org.json.JSONException;
 | 
			
		||||
@ -46,8 +41,6 @@ import java.io.FileInputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.text.CharacterIterator;
 | 
			
		||||
import java.text.StringCharacterIterator;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Timer;
 | 
			
		||||
@ -301,6 +294,8 @@ public class DownloadFragment extends Fragment {
 | 
			
		||||
    private View.OnClickListener ListenerDL = v -> {
 | 
			
		||||
        v.setEnabled(false);
 | 
			
		||||
        final LinearLayout layout = (LinearLayout) v.getParent();
 | 
			
		||||
        final Button button = layout.findViewById(R.id.file_download);
 | 
			
		||||
 | 
			
		||||
        final String name = (String) layout.getTag(R.id.ID_FILE_NAME);
 | 
			
		||||
        final String save_location = String.valueOf(layout.getTag(R.id.ID_SAVE_LOCATION));
 | 
			
		||||
        final long fileSize = (long) layout.getTag(R.id.ID_FILE_SIZE);
 | 
			
		||||
@ -309,11 +304,21 @@ public class DownloadFragment extends Fragment {
 | 
			
		||||
        new File(save_location).mkdirs();
 | 
			
		||||
        Uri uri = Uri.fromFile(new File(save_location, name));
 | 
			
		||||
 | 
			
		||||
        Intent intent = new Intent(getActivity(), TransferService.class);
 | 
			
		||||
        intent.setAction(TransferService.ACTION_DOWNLOAD);
 | 
			
		||||
        intent.putExtra(TransferService.EXTRA, new Extra(uri, name, fileSize, href, layout));
 | 
			
		||||
        getActivity().startService(intent);
 | 
			
		||||
        Transfer tr = new Transfer();
 | 
			
		||||
 | 
			
		||||
        new Thread(() -> {
 | 
			
		||||
            try {
 | 
			
		||||
                tr.downloadFile(uri, name, fileSize, href, button);
 | 
			
		||||
            } catch (IOException e) {
 | 
			
		||||
                final String ExceptionName = e.getClass().getSimpleName();
 | 
			
		||||
                final String ExceptionMess = e.getMessage();
 | 
			
		||||
 | 
			
		||||
                if(ExceptionName != null && ExceptionMess != null) {
 | 
			
		||||
                    Transfer.error(ExceptionName + ": " + ExceptionMess, null, null);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }).start();
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private View.OnClickListener ListenerShare = v -> {
 | 
			
		||||
@ -392,12 +397,12 @@ public class DownloadFragment extends Fragment {
 | 
			
		||||
    private List<View> getAllChildren(View v) {
 | 
			
		||||
 | 
			
		||||
        if (!(v instanceof ViewGroup)) {
 | 
			
		||||
            ArrayList<View> viewArrayList = new ArrayList<View>();
 | 
			
		||||
            ArrayList<View> viewArrayList = new ArrayList<>();
 | 
			
		||||
            viewArrayList.add(v);
 | 
			
		||||
            return viewArrayList;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ArrayList<View> result = new ArrayList<View>();
 | 
			
		||||
        ArrayList<View> result = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        ViewGroup viewGroup = (ViewGroup) v;
 | 
			
		||||
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
 | 
			
		||||
 | 
			
		||||
@ -15,10 +15,8 @@ import android.view.ViewGroup;
 | 
			
		||||
import android.widget.Button;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
 | 
			
		||||
import com.localtransfer.MainActivity;
 | 
			
		||||
import com.localtransfer.R;
 | 
			
		||||
import com.localtransfer.Transfer;
 | 
			
		||||
import com.localtransfer.TransferService;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
@ -91,11 +89,7 @@ public class UploadFragment extends Fragment {
 | 
			
		||||
                    fileUris.add(uri);
 | 
			
		||||
                }
 | 
			
		||||
                for (Uri uri : fileUris) {
 | 
			
		||||
                    Intent intent = new Intent(getActivity(), TransferService.class);
 | 
			
		||||
                    intent.setAction(TransferService.ACTION_UPLOAD);
 | 
			
		||||
                    intent.putExtra(TransferService.EXTRA_URI, uri);
 | 
			
		||||
                    getActivity().startService(intent);
 | 
			
		||||
                    //tr.handleSendFile(uri);
 | 
			
		||||
                    tr.handleSendFile(uri);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user