fixed some bugs

This commit is contained in:
Christian Schabesberger 2016-02-29 20:33:28 +01:00
parent 18493a578d
commit 028354b283
6 changed files with 46 additions and 23 deletions

View File

@ -114,6 +114,7 @@ public class ErrorActivity extends AppCompatActivity {
ActivityCommunicator ac = ActivityCommunicator.getCommunicator(); ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
ac.errorList = el; ac.errorList = el;
ac.returnActivity = returnAcitivty; ac.returnActivity = returnAcitivty;
ac.errorInfo = errorInfo;
Intent intent = new Intent(context, ErrorActivity.class); Intent intent = new Intent(context, ErrorActivity.class);
context.startActivity(intent); context.startActivity(intent);
} }

View File

@ -134,13 +134,14 @@ public class VideoItemListFragment extends ListFragment {
} }
// hard errors: // hard errors:
} catch(IOException e) { } catch(IOException e) {
postNewErrorToast(h, R.string.network_error); postNewNothingFoundToast(h, R.string.network_error);
e.printStackTrace(); e.printStackTrace();
} catch(SearchEngine.NothingFoundException e) {
postNewErrorToast(h, e.getMessage());
} catch(ExtractionException e) { } catch(ExtractionException e) {
ErrorActivity.reportError(h, getActivity(), e, null, null, ErrorActivity.reportError(h, getActivity(), e, null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error)); /* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error));
//postNewErrorToast(h, R.string.parsing_error); //postNewErrorToast(h, R.string.parsing_error);
e.printStackTrace(); e.printStackTrace();
@ -197,12 +198,11 @@ public class VideoItemListFragment extends ListFragment {
private void updateListOnResult(SearchResult result, int requestId) { private void updateListOnResult(SearchResult result, int requestId) {
if(requestId == currentRequestId) { if(requestId == currentRequestId) {
setListShown(true); setListShown(true);
if (!result.resultList.isEmpty()) { updateList(result.resultList);
if (!result.suggestion.isEmpty()) { if(!result.suggestion.isEmpty()) {
Toast.makeText(getActivity(), getString(R.string.did_you_mean) + result.suggestion + " ?", Toast.makeText(getActivity(),
Toast.LENGTH_LONG).show(); String.format(getString(R.string.did_you_mean), result.suggestion),
} Toast.LENGTH_LONG).show();
updateList(result.resultList);
} }
} }
} }
@ -344,13 +344,24 @@ public class VideoItemListFragment extends ListFragment {
mActivatedPosition = position; mActivatedPosition = position;
} }
private void postNewErrorToast(Handler h, final int stringResource) { private void postNewErrorToast(Handler h, final String message) {
h.post(new Runnable() {
@Override
public void run() {
setListShown(true);
Toast.makeText(getActivity(), message,
Toast.LENGTH_SHORT).show();
}
});
}
private void postNewNothingFoundToast(Handler h, final int stringResource) {
h.post(new Runnable() { h.post(new Runnable() {
@Override @Override
public void run() { public void run() {
setListShown(true); setListShown(true);
Toast.makeText(getActivity(), getString(stringResource), Toast.makeText(getActivity(), getString(stringResource),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_LONG).show();
} }
}); });
} }

View File

@ -27,6 +27,12 @@ import java.util.Vector;
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
public interface SearchEngine { public interface SearchEngine {
public class NothingFoundException extends ExtractionException {
public NothingFoundException(String message) {
super(message);
}
}
ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl) ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
throws ExtractionException, IOException; throws ExtractionException, IOException;

View File

@ -28,11 +28,12 @@ public class SearchResult {
public static SearchResult getSearchResult(SearchEngine engine, String query, public static SearchResult getSearchResult(SearchEngine engine, String query,
int page, String languageCode, Downloader dl) int page, String languageCode, Downloader dl)
throws ExtractionException, IOException { throws ExtractionException, IOException {
try {
return engine.search(query, page, languageCode, dl).getSearchResult(); SearchResult result = engine.search(query, page, languageCode, dl).getSearchResult();
} catch (Exception e) { if(result.resultList.isEmpty()) {
throw new ExtractionException("Could not get any search result", e); throw new ExtractionException("Empty result despite no error");
} }
return result;
} }
public String suggestion = ""; public String suggestion = "";

View File

@ -7,6 +7,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.ExtractionException;
import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.Parser;
import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ParsingException;
import org.schabi.newpipe.extractor.SearchEngine; import org.schabi.newpipe.extractor.SearchEngine;
@ -52,7 +53,7 @@ public class YoutubeSearchEngine implements SearchEngine {
@Override @Override
public StreamPreviewInfoCollector search(String query, int page, String languageCode, Downloader downloader) public StreamPreviewInfoCollector search(String query, int page, String languageCode, Downloader downloader)
throws IOException, ParsingException { throws IOException, ExtractionException {
StreamPreviewInfoCollector collector = new StreamPreviewInfoCollector( StreamPreviewInfoCollector collector = new StreamPreviewInfoCollector(
new YoutubeStreamUrlIdHandler()); new YoutubeStreamUrlIdHandler());
Uri.Builder builder = new Uri.Builder(); Uri.Builder builder = new Uri.Builder();
@ -98,7 +99,7 @@ public class YoutubeSearchEngine implements SearchEngine {
// search message item // search message item
} else if (!((el = item.select("div[class*=\"search-message\"]").first()) == null)) { } else if (!((el = item.select("div[class*=\"search-message\"]").first()) == null)) {
//result.errorMessage = el.text(); //result.errorMessage = el.text();
throw new StreamExtractor.ContentNotAvailableException(el.text()); throw new NothingFoundException(el.text());
// video item type // video item type
} else if (!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) { } else if (!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) {
@ -211,8 +212,6 @@ public class YoutubeSearchEngine implements SearchEngine {
@Override @Override
public long getViewCount() throws ParsingException { public long getViewCount() throws ParsingException {
throw new ParsingException("blabla");
/*
String output; String output;
String input = item.select("div[class=\"yt-lockup-meta\"]").first() String input = item.select("div[class=\"yt-lockup-meta\"]").first()
.select("li").get(1) .select("li").get(1)
@ -222,11 +221,16 @@ public class YoutubeSearchEngine implements SearchEngine {
.replace(".", "") .replace(".", "")
.replace(",", ""); .replace(",", "");
if(Long.parseLong(output) == 30) { try {
Log.d(TAG, "bla"); return Long.parseLong(output);
} catch (NumberFormatException e) {
// if this happens the video probably has no views
if(!input.isEmpty()) {
return 0;
} else {
throw new ParsingException("Could not handle input: " + input, e);
}
} }
return Long.parseLong(output);
*/
} }
@Override @Override

View File

@ -15,7 +15,7 @@
<string name="download">Download</string> <string name="download">Download</string>
<string name="search">Search</string> <string name="search">Search</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="did_you_mean">Did you mean: </string> <string name="did_you_mean">Did you mean: %1$s ?</string>
<string name="search_page">Search page: </string> <string name="search_page">Search page: </string>
<string name="share_dialog_title">Share with:</string> <string name="share_dialog_title">Share with:</string>
<string name="choose_browser">Choose browser:</string> <string name="choose_browser">Choose browser:</string>