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();
ac.errorList = el;
ac.returnActivity = returnAcitivty;
ac.errorInfo = errorInfo;
Intent intent = new Intent(context, ErrorActivity.class);
context.startActivity(intent);
}

View File

@ -134,13 +134,14 @@ public class VideoItemListFragment extends ListFragment {
}
// hard errors:
} catch(IOException e) {
postNewErrorToast(h, R.string.network_error);
postNewNothingFoundToast(h, R.string.network_error);
e.printStackTrace();
} catch(SearchEngine.NothingFoundException e) {
postNewErrorToast(h, e.getMessage());
} catch(ExtractionException e) {
ErrorActivity.reportError(h, getActivity(), e, null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error));
//postNewErrorToast(h, R.string.parsing_error);
e.printStackTrace();
@ -197,12 +198,11 @@ public class VideoItemListFragment extends ListFragment {
private void updateListOnResult(SearchResult result, int requestId) {
if(requestId == currentRequestId) {
setListShown(true);
if (!result.resultList.isEmpty()) {
if (!result.suggestion.isEmpty()) {
Toast.makeText(getActivity(), getString(R.string.did_you_mean) + result.suggestion + " ?",
Toast.LENGTH_LONG).show();
}
updateList(result.resultList);
updateList(result.resultList);
if(!result.suggestion.isEmpty()) {
Toast.makeText(getActivity(),
String.format(getString(R.string.did_you_mean), result.suggestion),
Toast.LENGTH_LONG).show();
}
}
}
@ -344,13 +344,24 @@ public class VideoItemListFragment extends ListFragment {
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() {
@Override
public void run() {
setListShown(true);
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")
public interface SearchEngine {
public class NothingFoundException extends ExtractionException {
public NothingFoundException(String message) {
super(message);
}
}
ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
throws ExtractionException, IOException;

View File

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

View File

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

View File

@ -15,7 +15,7 @@
<string name="download">Download</string>
<string name="search">Search</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="share_dialog_title">Share with:</string>
<string name="choose_browser">Choose browser:</string>