Delete TransferService revert to native DL/UP
This commit is contained in:
		
							
								
								
									
										43
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										43
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @ -1,5 +1,48 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <project version="4"> | <project version="4"> | ||||||
|  |   <component name="NullableNotNullManager"> | ||||||
|  |     <option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" /> | ||||||
|  |     <option name="myDefaultNotNull" value="androidx.annotation.NonNull" /> | ||||||
|  |     <option name="myNullables"> | ||||||
|  |       <value> | ||||||
|  |         <list size="14"> | ||||||
|  |           <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> | ||||||
|  |           <item index="1" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> | ||||||
|  |           <item index="2" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> | ||||||
|  |           <item index="3" class="java.lang.String" itemvalue="androidx.annotation.Nullable" /> | ||||||
|  |           <item index="4" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" /> | ||||||
|  |           <item index="5" class="java.lang.String" itemvalue="com.android.annotations.Nullable" /> | ||||||
|  |           <item index="6" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> | ||||||
|  |           <item index="7" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" /> | ||||||
|  |           <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" /> | ||||||
|  |           <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" /> | ||||||
|  |           <item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" /> | ||||||
|  |           <item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" /> | ||||||
|  |           <item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" /> | ||||||
|  |           <item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" /> | ||||||
|  |         </list> | ||||||
|  |       </value> | ||||||
|  |     </option> | ||||||
|  |     <option name="myNotNulls"> | ||||||
|  |       <value> | ||||||
|  |         <list size="13"> | ||||||
|  |           <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> | ||||||
|  |           <item index="1" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> | ||||||
|  |           <item index="2" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> | ||||||
|  |           <item index="3" class="java.lang.String" itemvalue="androidx.annotation.NonNull" /> | ||||||
|  |           <item index="4" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" /> | ||||||
|  |           <item index="5" class="java.lang.String" itemvalue="com.android.annotations.NonNull" /> | ||||||
|  |           <item index="6" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> | ||||||
|  |           <item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" /> | ||||||
|  |           <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" /> | ||||||
|  |           <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" /> | ||||||
|  |           <item index="10" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" /> | ||||||
|  |           <item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" /> | ||||||
|  |           <item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" /> | ||||||
|  |         </list> | ||||||
|  |       </value> | ||||||
|  |     </option> | ||||||
|  |   </component> | ||||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | ||||||
|     <output url="file://$PROJECT_DIR$/build/classes" /> |     <output url="file://$PROJECT_DIR$/build/classes" /> | ||||||
|   </component> |   </component> | ||||||
|  | |||||||
| @ -14,9 +14,6 @@ | |||||||
|         android:supportsRtl="true" |         android:supportsRtl="true" | ||||||
|         android:theme="@style/AppTheme"> |         android:theme="@style/AppTheme"> | ||||||
|  |  | ||||||
|         <service |  | ||||||
|             android:name=".TransferService" /> |  | ||||||
|  |  | ||||||
|         <provider |         <provider | ||||||
|             android:name="androidx.core.content.FileProvider" |             android:name="androidx.core.content.FileProvider" | ||||||
|             android:authorities="${applicationId}" |             android:authorities="${applicationId}" | ||||||
|  | |||||||
| @ -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 androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | ||||||
|  |  | ||||||
| import android.os.Environment; | import android.os.Environment; | ||||||
| import android.os.Parcelable; |  | ||||||
| import android.util.Log; |  | ||||||
| import android.view.ContextMenu; | import android.view.ContextMenu; | ||||||
| import android.view.Gravity; | import android.view.Gravity; | ||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| @ -23,18 +21,15 @@ import android.view.ViewGroup; | |||||||
| import android.view.animation.Animation; | import android.view.animation.Animation; | ||||||
| import android.view.animation.LinearInterpolator; | import android.view.animation.LinearInterpolator; | ||||||
| import android.widget.Button; | import android.widget.Button; | ||||||
| import android.widget.FrameLayout; |  | ||||||
| import android.widget.ImageView; | import android.widget.ImageView; | ||||||
| import android.widget.LinearLayout; | import android.widget.LinearLayout; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
|  |  | ||||||
| import com.google.android.material.snackbar.Snackbar; | import com.google.android.material.snackbar.Snackbar; | ||||||
| import com.localtransfer.BuildConfig; | import com.localtransfer.BuildConfig; | ||||||
| import com.localtransfer.Extra; |  | ||||||
| import com.localtransfer.Progress; | import com.localtransfer.Progress; | ||||||
| import com.localtransfer.R; | import com.localtransfer.R; | ||||||
| import com.localtransfer.Transfer; | import com.localtransfer.Transfer; | ||||||
| import com.localtransfer.TransferService; |  | ||||||
|  |  | ||||||
| import org.json.JSONArray; | import org.json.JSONArray; | ||||||
| import org.json.JSONException; | import org.json.JSONException; | ||||||
| @ -46,8 +41,6 @@ import java.io.FileInputStream; | |||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||||
| import java.text.CharacterIterator; |  | ||||||
| import java.text.StringCharacterIterator; |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Timer; | import java.util.Timer; | ||||||
| @ -301,6 +294,8 @@ public class DownloadFragment extends Fragment { | |||||||
|     private View.OnClickListener ListenerDL = v -> { |     private View.OnClickListener ListenerDL = v -> { | ||||||
|         v.setEnabled(false); |         v.setEnabled(false); | ||||||
|         final LinearLayout layout = (LinearLayout) v.getParent(); |         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 name = (String) layout.getTag(R.id.ID_FILE_NAME); | ||||||
|         final String save_location = String.valueOf(layout.getTag(R.id.ID_SAVE_LOCATION)); |         final String save_location = String.valueOf(layout.getTag(R.id.ID_SAVE_LOCATION)); | ||||||
|         final long fileSize = (long) layout.getTag(R.id.ID_FILE_SIZE); |         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(); |         new File(save_location).mkdirs(); | ||||||
|         Uri uri = Uri.fromFile(new File(save_location, name)); |         Uri uri = Uri.fromFile(new File(save_location, name)); | ||||||
|  |  | ||||||
|         Intent intent = new Intent(getActivity(), TransferService.class); |         Transfer tr = new Transfer(); | ||||||
|         intent.setAction(TransferService.ACTION_DOWNLOAD); |  | ||||||
|         intent.putExtra(TransferService.EXTRA, new Extra(uri, name, fileSize, href, layout)); |  | ||||||
|         getActivity().startService(intent); |  | ||||||
|  |  | ||||||
|  |         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 -> { |     private View.OnClickListener ListenerShare = v -> { | ||||||
| @ -392,12 +397,12 @@ public class DownloadFragment extends Fragment { | |||||||
|     private List<View> getAllChildren(View v) { |     private List<View> getAllChildren(View v) { | ||||||
|  |  | ||||||
|         if (!(v instanceof ViewGroup)) { |         if (!(v instanceof ViewGroup)) { | ||||||
|             ArrayList<View> viewArrayList = new ArrayList<View>(); |             ArrayList<View> viewArrayList = new ArrayList<>(); | ||||||
|             viewArrayList.add(v); |             viewArrayList.add(v); | ||||||
|             return viewArrayList; |             return viewArrayList; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         ArrayList<View> result = new ArrayList<View>(); |         ArrayList<View> result = new ArrayList<>(); | ||||||
|  |  | ||||||
|         ViewGroup viewGroup = (ViewGroup) v; |         ViewGroup viewGroup = (ViewGroup) v; | ||||||
|         for (int i = 0; i < viewGroup.getChildCount(); i++) { |         for (int i = 0; i < viewGroup.getChildCount(); i++) { | ||||||
|  | |||||||
| @ -15,10 +15,8 @@ import android.view.ViewGroup; | |||||||
| import android.widget.Button; | import android.widget.Button; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
|  |  | ||||||
| import com.localtransfer.MainActivity; |  | ||||||
| import com.localtransfer.R; | import com.localtransfer.R; | ||||||
| import com.localtransfer.Transfer; | import com.localtransfer.Transfer; | ||||||
| import com.localtransfer.TransferService; |  | ||||||
|  |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  |  | ||||||
| @ -91,11 +89,7 @@ public class UploadFragment extends Fragment { | |||||||
|                     fileUris.add(uri); |                     fileUris.add(uri); | ||||||
|                 } |                 } | ||||||
|                 for (Uri uri : fileUris) { |                 for (Uri uri : fileUris) { | ||||||
|                     Intent intent = new Intent(getActivity(), TransferService.class); |                     tr.handleSendFile(uri); | ||||||
|                     intent.setAction(TransferService.ACTION_UPLOAD); |  | ||||||
|                     intent.putExtra(TransferService.EXTRA_URI, uri); |  | ||||||
|                     getActivity().startService(intent); |  | ||||||
|                     //tr.handleSendFile(uri); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 lionel
					lionel