mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-11-04 00:33:55 +01:00 
			
		
		
		
	Merge remote-tracking branch 'refs/remotes/origin/api-calls' into cache-area-categories
This commit is contained in:
		
						commit
						75e3da7ea2
					
				
					 4 changed files with 33 additions and 28 deletions
				
			
		| 
						 | 
					@ -26,6 +26,7 @@ import java.util.ArrayList;
 | 
				
			||||||
import java.util.Date;
 | 
					import java.util.Date;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
 | 
					import java.util.concurrent.ScheduledThreadPoolExecutor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class CategorizationFragment extends SherlockFragment{
 | 
					public class CategorizationFragment extends SherlockFragment{
 | 
				
			||||||
| 
						 | 
					@ -150,9 +151,9 @@ public class CategorizationFragment extends SherlockFragment{
 | 
				
			||||||
                        items.add(cat.getName());
 | 
					                        items.add(cat.getName());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (MwVolleyApi.gpsCatExists){
 | 
					                    if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true){
 | 
				
			||||||
                        Log.d("Cat", "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString());
 | 
					                        Log.d("Cat", "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString());
 | 
				
			||||||
                        ArrayList<String> gpsItems = new ArrayList<String>(MwVolleyApi.getGpsCat());
 | 
					                        List<String> gpsItems = new ArrayList<String>(MwVolleyApi.getGpsCat());
 | 
				
			||||||
                        Log.d("Cat", "GPS items: " + gpsItems.toString());
 | 
					                        Log.d("Cat", "GPS items: " + gpsItems.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        mergedItems.addAll(gpsItems);
 | 
					                        mergedItems.addAll(gpsItems);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,9 +48,7 @@ public class FilePathConverter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Log.d("Image", "File path: " + filePath);
 | 
					            Log.d("Image", "File path: " + filePath);
 | 
				
			||||||
            return filePath;
 | 
					            return filePath;
 | 
				
			||||||
        }
 | 
					        } catch (IllegalArgumentException e) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
            Log.w("Image", e);
 | 
					            Log.w("Image", e);
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,6 @@ public class GPSExtractor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            exif = new ExifInterface(filePath);
 | 
					            exif = new ExifInterface(filePath);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            Log.w("Image", e);
 | 
					            Log.w("Image", e);
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,18 +22,18 @@ import java.io.UnsupportedEncodingException;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class MwVolleyApi {
 | 
					public class MwVolleyApi {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static RequestQueue REQUEST_QUEUE;
 | 
					    private static RequestQueue REQUEST_QUEUE;
 | 
				
			||||||
    private static final Gson GSON = new GsonBuilder().create();
 | 
					    private static final Gson GSON = new GsonBuilder().create();
 | 
				
			||||||
    private Context context;
 | 
					    private Context context;
 | 
				
			||||||
    private static String coordsLog;
 | 
					    private String coordsLog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected static HashSet<String> categorySet;
 | 
					    protected static Set<String> categorySet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //To check later on whether any nearby categories were found
 | 
					    private static final String MWURL = "https://commons.wikimedia.org/";
 | 
				
			||||||
    public static boolean gpsCatExists;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public MwVolleyApi(Context context) {
 | 
					    public MwVolleyApi(Context context) {
 | 
				
			||||||
        this.context = context;
 | 
					        this.context = context;
 | 
				
			||||||
| 
						 | 
					@ -41,8 +41,8 @@ public class MwVolleyApi {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //To get the list of categories for display
 | 
					    //To get the list of categories for display
 | 
				
			||||||
    public static ArrayList<String> getGpsCat() {
 | 
					    public static List<String> getGpsCat() {
 | 
				
			||||||
        ArrayList<String> list = new ArrayList<String>(categorySet);
 | 
					        List<String> list = new ArrayList<String>(categorySet);
 | 
				
			||||||
        return list;
 | 
					        return list;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,7 +73,7 @@ public class MwVolleyApi {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private String buildUrl (String coords, int ggsradius){
 | 
					    private String buildUrl (String coords, int ggsradius){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Uri.Builder builder = Uri.parse("https://commons.wikimedia.org/").buildUpon();
 | 
					        Uri.Builder builder = Uri.parse(MWURL).buildUpon();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        builder.appendPath("w")
 | 
					        builder.appendPath("w")
 | 
				
			||||||
                .appendPath("api.php")
 | 
					                .appendPath("api.php")
 | 
				
			||||||
| 
						 | 
					@ -154,29 +154,39 @@ public class MwVolleyApi {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static class GpsCatExists {
 | 
				
			||||||
 | 
					        private static boolean gpsCatExists;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static void setGpsCatExists(boolean gpsCat) {
 | 
				
			||||||
 | 
					            gpsCatExists = gpsCat;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static boolean getGpsCatExists() {
 | 
				
			||||||
 | 
					            return gpsCatExists;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static class QueryResponse {
 | 
					    private static class QueryResponse {
 | 
				
			||||||
        private Query query = new Query();
 | 
					        private Query query = new Query();
 | 
				
			||||||
        private Page page;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private String printSet() {
 | 
					        private String printSet() {
 | 
				
			||||||
            if (categorySet == null || categorySet.isEmpty()) {
 | 
					            if (categorySet == null || categorySet.isEmpty()) {
 | 
				
			||||||
                gpsCatExists = false;
 | 
					                GpsCatExists.setGpsCatExists(false);
 | 
				
			||||||
                Log.d("Cat", "gpsCatExists=" + gpsCatExists);
 | 
					                Log.d("Cat", "gpsCatExists=" + GpsCatExists.getGpsCatExists());
 | 
				
			||||||
                return "No collection of categories";
 | 
					                return "No collection of categories";
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else {
 | 
					                GpsCatExists.setGpsCatExists(true);
 | 
				
			||||||
                gpsCatExists = true;
 | 
					                Log.d("Cat", "gpsCatExists=" + GpsCatExists.getGpsCatExists());
 | 
				
			||||||
                Log.d("Cat", "gpsCatExists=" + gpsCatExists);
 | 
					 | 
				
			||||||
                return "CATEGORIES FOUND" + categorySet.toString();
 | 
					                return "CATEGORIES FOUND" + categorySet.toString();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
        public String toString() {
 | 
					        public String toString() {
 | 
				
			||||||
            if (query!=null) {
 | 
					            if (query != null) {
 | 
				
			||||||
                return "query=" + query.toString() + "\n" + printSet();
 | 
					                return "query=" + query.toString() + "\n" + printSet();
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else {
 | 
					                return "No pages found";
 | 
				
			||||||
                return "No pages found near " + coordsLog;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -212,16 +222,13 @@ public class MwVolleyApi {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (categories == null || categories.length == 0) {
 | 
					            if (categories == null || categories.length == 0) {
 | 
				
			||||||
                builder.append("no categories exist\n");
 | 
					                builder.append("no categories exist\n");
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                for (Category category : categories) {
 | 
					                for (Category category : categories) {
 | 
				
			||||||
                    builder.append(category.toString());
 | 
					                    builder.append(category.toString());
 | 
				
			||||||
                    builder.append("\n");
 | 
					                    builder.append("\n");
 | 
				
			||||||
                    if (category != null) {
 | 
					                    if (category != null) {
 | 
				
			||||||
                        String categoryString = category.toString().replace("Category:", "");
 | 
					                        String categoryString = category.toString().replace("Category:", "");
 | 
				
			||||||
                        categorySet.add(categoryString);
 | 
					                        categorySet.add(categoryString);
 | 
				
			||||||
                        //Log.d("Set", "category added: " + category.toString());
 | 
					 | 
				
			||||||
                        //Log.d("Set", "Current category Set" + categorySet.toString());
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue